Configuration and required jar package for springmvc environment construction

1. web.xml configuration

  <!-- Load spring configuration file-->

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/Spring.xml</param-value><!-- ,/WEB-INF/Spring-Mybatis.xml -->

</context-param>

 

<servlet>

<servlet-name>dispatcherServlet</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<!-- SpringMVC configuration file-->

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/SpringMVC.xml</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>dispatcherServlet</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

 

<filter>

<description>Character set filter</description>

<filter-name>encodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<description>Character set encoding</description>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>encodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

 

<!-- Spring's listener -->

<listener>

<description>spring监听器</description>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

 

<!-- Prevent spring memory overflow listener -->

<listener>

<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>

</listener>

 

2. Spring.xml configuration

 

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:util="http://www.springframework.org/schema/util"

xsi:schemaLocation="

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd    

http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd

">

<mvc:annotation-driven/>

<!--Introduce properties file -->

<!--<context:property-placeholder location="classpath:jdbc.properties" />-->

<!-- service和dao包(自动注入) -->

<context:component-scan base-package="com.service,com.service.impl,com.po" /> 

 

</beans>

 

3.SpringMVC.xml 配置

 

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"

xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:util="http://www.springframework.org/schema/util"

xsi:schemaLocation="

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd    

        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd

">

<mvc:annotation-driven />  <!-- 支持spring3.0新的mvc注解 -->

<context:component-scan base-package="com.controller" />

 

<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->

<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">

<property name="supportedMediaTypes">

<list>

<value>text/html;charset=UTF-8</value>

</list>

</property>

</bean>

 

<!-- 启动Spring MVC 的注解功能,完成请求和注解POJO的映射 -->

<bean

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

<property name="messageConverters">

<list>

<ref bean="mappingJacksonHttpMessageConverter" />  <!-- json转换器 -->

</list>

</property>

</bean>

 

<!-- 页面View层基本信息设定 -->

<bean id="viewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"  class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="viewClass"value="org.springframework.web.servlet.view.JstlView" />

</bean>

 

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

<property name="defaultEncoding" value="UTF-8" />

<property name="maxUploadSize" value="32505856" /><!-- 上传文件大小限制为31M,31*1024*1024 -->

<property name="maxInMemorySize" value="4096" />

</bean>

 

</beans>

 

以上就是简单的配置,附件是所需的jar包。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326245544&siteId=291194637