spring-mvc.xml 5.08 KB
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources/ directory -->
	<resources mapping="/resource/**" location="/resource/" />
	<resources mapping="/probe/**" location="/probe/" />

	<context:component-scan base-package="com.cjs.cms.action" use-default-filters="false">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
	</context:component-scan>
	
	<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
		<mvc:message-converters register-defaults="true">
			<!-- 解决AJAX中文乱码 -->
			<beans:bean class="org.springframework.http.converter.StringHttpMessageConverter">
				<beans:constructor-arg value="UTF-8" />
			</beans:bean>
			<beans:bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
				<beans:property name="objectMapper" ref="jacksonObjectMapper" />
				<beans:property name="prettyPrint" value="false"></beans:property>
			</beans:bean>
			<beans:bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
		</mvc:message-converters>
	</mvc:annotation-driven>
	
	<!-- 容器默认的DefaultServletHandler处理 所有静态内容与无RequestMapping处理的URL-->	
	<mvc:default-servlet-handler/>

	<!--1、检查扩展名(如my.pdf);2、检查Parameter(如my?format=pdf);3、检查Accept Header -->
	<beans:bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
		<!-- 扩展名至mimeType的映射,即 /user.json => application/json -->
		<beans:property name="favorPathExtension" value="true" />
		<!-- 用于开启 /userinfo/123?format=json 的支持 -->
		<beans:property name="favorParameter" value="true" />
		<beans:property name="parameterName" value="format" />
		<!-- 是否忽略Accept Header -->
		<beans:property name="ignoreAcceptHeader" value="false" />
		<!--扩展名到MIME的映射;favorPathExtension, favorParameter是true时起作用 -->
		<beans:property name="mediaTypes">
			<beans:map>
				<beans:entry key="json" value="application/json" />
				<beans:entry key="xml" value="text/xml" />
				<beans:entry key="html" value="text/html" />
			</beans:map>
		</beans:property>
		<!-- 默认的content type -->
		<beans:property name="defaultContentType" value="application/json" />
	</beans:bean>

	<!-- 内容协商视图解析器;根据客户端不同的请求决定不同的view进行响应 -->
	<!-- 会自动根据解析的contentType来决定使用哪个视图解析器(默认使用整个web应用中的viewResolver) -->
	<beans:bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<!-- 内容协商管理器 用于决定media type -->
		<beans:property name="contentNegotiationManager" ref="contentNegotiationManager" />
	</beans:bean>

	<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
	<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<beans:property name="prefix" value="/WEB-INF/view/" />
		<!-- <beans:property name="suffix" value=".jsp" /> -->
	</beans:bean>
	
	<!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->  
	<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
		<beans:property name="defaultEncoding" value="UTF-8"/>
		<!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->  
		<beans:property name="maxUploadSize" value="2000000000"/>
	</beans:bean>  

	<mvc:view-controller path="/" view-name="index.jsp" />
	
	<!-- 拦截器 -->
	<mvc:interceptors>
		<mvc:interceptor>
			<mvc:mapping path="/**"/>
			<mvc:exclude-mapping path="/pub/**" />
			<mvc:exclude-mapping path="/resource/**"/>
			<mvc:exclude-mapping path="/probe/**" />
			<mvc:exclude-mapping path="/pnr/**" />
			<mvc:exclude-mapping path="/sendMessage/callBack" />
			<beans:bean class="com.cjs.cms.action.interceptor.SecurityInterceptor"/>
		</mvc:interceptor>
	</mvc:interceptors>
</beans:beans>