<?xml version="1.0" encoding="UTF-8"?>
<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:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">

	<!-- 配置自定扫描的包,仅handler和Advice -->
	<context:component-scan base-package="com.iamberry" use-default-filters="false">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
		<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
	</context:component-scan>
    
	<!-- 配置JSP视图解析器: 如何把 handler 方法返回值解析为实际的物理视图 -->
	<bean id="viewResolverJsp" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="contentType" value="text/html; charset=UTF-8"/>
		<property name="prefix" value="/WEB-INF/views/"></property>
		<property name="suffix" value=".jsp"></property>
        <property name="order" value="1"/> 
	</bean>
	
	<!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的，而且此时还没有进入到Controller方法中   遇到MaxUploadSizeExceededException异常时，自动跳转到/WEB-INF/views/msg/ploadToSize.jsp页面 -->  
    <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">  
        <property name="exceptionMappings">  
            <props>  
                <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">/msg/ploadToSize</prop>  
            </props>  
        </property>  
    </bean>
    
	<!-- 解决静态资源,提供两种方法 -->
	<mvc:default-servlet-handler/>
	<mvc:resources location="/common/" mapping="/common/**" />
	
	<!-- 解决配置mvc:default-servlet-handler后，前台handler方法失效问 -->
	<mvc:annotation-driven>
		<!-- 配置@ResponseBody后，如果返回为Entity，有null的数据返回，增大返回数据大小 -->
        <mvc:message-converters>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
                <property name="objectMapper">  
                    <bean class="com.fasterxml.jackson.databind.ObjectMapper">
                        <!-- 为null字段时不显示 -->
                        <property name="serializationInclusion">
                            <value type="com.fasterxml.jackson.annotation.JsonInclude.Include">NON_NULL</value>
                        </property> 
                    </bean>  
                </property>  
            </bean>  
        </mvc:message-converters>  
	</mvc:annotation-driven>
	
	<!-- 配置MultipartResolver -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 默认的编码 -->
		<property name="defaultEncoding" value="UTF-8"></property>
		<!-- 最大上传大小 -->
		<property name="maxUploadSize" value="1024000"></property>
	</bean>
	
	<!--避免IE执行AJAX时，返回JSON出现下载文件 -->  
    <bean id="mappingJacksonHttpMessageConverter"  class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">  
        <property name="supportedMediaTypes">  
            <list>  
               <value>text/html; charset=UTF-8</value>  
               <value>application/json;charset=UTF-8</value>  
            </list>  
        </property>  
    </bean>
    <bean  class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">  
        <property name="messageConverters">  
            <list>  
                <ref bean="mappingJacksonHttpMessageConverter" />
            </list>  
        </property>  
    </bean>
</beans>
