<?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">
	
	<!-- 该异常是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>
	<!-- 配置自定扫描的包,仅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>
	
	<!-- 配置freeMarker视图解析器 -->
    <!--<bean id="viewResolverFtl" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
        <property name="contentType" value="text/html; charset=UTF-8"/>
        <property name="exposeRequestAttributes" value="true" />
        <property name="exposeSessionAttributes" value="true" />
        <property name="exposeSpringMacroHelpers" value="true" />
        <property name="requestContextAttribute" value="request"/>
        <property name="cache" value="true" />
        <property name="suffix" value=".ftl" />
        <property name="order" value="0"/>
    </bean>-->

    <!--&lt;!&ndash; 配置FREEMARKER的视图解析器 &ndash;&gt;
    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/WEB-INF/views/"/>
        <property name="freemarkerVariables">
            <map>
                <entry key="xml_escape" value-ref="fmXmlEscape" />
            </map>
        </property>
        <property name="defaultEncoding" value="UTF-8"/>
        <property name="freemarkerSettings">
            <props>
            	&lt;!&ndash; 指定更新模版文件的间隔时间，相当于多长时间检测一下是否有必要重新加载模版文件，0 表示每次都重新加载，否则为多少毫秒钟检测一下模版是否更改  &ndash;&gt;
                <prop key="template_update_delay">3600</prop>
                <prop key="locale">zh_CN</prop>
                <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
                <prop key="date_format">yyyy-MM-dd</prop>
                <prop key="number_format">#.##</prop>
            </props>
        </property>
    </bean>
    <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>-->
    
	<!-- 配置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>
	
	<!-- 解决静态资源,提供两种方法 -->
	<mvc:default-servlet-handler/>
	<mvc:resources location="/common/css/" mapping="/common/css/**" />
	<mvc:resources location="/common/images/" mapping="/common/images/**" />
	<mvc:resources location="/common/js/" mapping="/common/js/**" />
	<mvc:resources location="/common/other/" mapping="/common/other/**" />
	<!--<mvc:resources location="/common/" mapping="/common/**" />  
	<mvc:resources location="/css/" mapping="/css/**" />  
	<mvc:resources location="/image/" mapping="/image/**" />  
	<mvc:resources location="/ueditor/" mapping="/ueditor/**" />  -->
    <!-- 解决配置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="1024000000"></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>
