<?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-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">
    
    <description>Spring MVC Configuration</description>
    
   <!-- 加载配置属性文件 -->
   <!-- <context:property-placeholder ignore-unresolvable="true" location="classpath:ejweb.properties" />-->
    <bean id="propertyConfigurer" class="com.ejweb.core.security.SecurityPropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:ejweb.properties</value>
            </list>
        </property>
    </bean>
    <!-- 使用Annotation自动注册Bean,只扫描@Controller -->
    <context:component-scan base-package="com.ejweb" use-default-filters="false"><!-- base-package 如果多个，用“,”分隔 -->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    
    <!-- REST中根据URL后缀自动判定Content-Type及相应的View -->
    <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
        <property name="mediaTypes">
            <map>
                <entry key="json" value="application/json"/>
                <entry key="xml" value="application/xml;charset=utf-8"/>
            </map>
        </property>
        <!-- 扩展名至mimeType的映射,即 /user.json => application/json -->
        <property name= "favorPathExtension" value= "true" />
        <!-- 用于开启 /userinfo/123?format=json 的支持 -->
        <property name= "favorParameter" value= "true" />
        <property name= "parameterName" value= "format"/>
        <!-- 是否忽略Accept Header -->
        <property name="ignoreAcceptHeader" value="false"/>
        <!-- 默认的content type -->
        <property name= "defaultContentType" value= "application/json" />
    </bean>
    
    <!-- 默认的注解映射的支持 -->
    <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
        <mvc:message-converters register-defaults="true">
            <!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter">
                <constructor-arg value="UTF-8" />
            </bean>
            <!-- 配置Fastjson支持 -->
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/plain;charset=UTF-8</value>
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
                <property name="features">
                    <list>
                        <value>WriteMapNullValue</value>
                        <value>QuoteFieldNames</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>
    <!-- Freemarker的配置 -->
    <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape"/>
    <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="${web.view.prefix}"/>
        <property name="defaultEncoding" value="utf-8"/>
        <property name="freemarkerVariables">
            <map>
                <entry key="xml_escape" value-ref="fmXmlEscape"/>
            </map>
        </property>
        <property name="freemarkerSettings">
            <props>
                <prop key="template_update_delay">1</prop>
                <prop key="default_encoding">UTF-8</prop>
                <prop key="output_encoding">UTF-8</prop>
                <prop key="locale">zh_CN</prop>
                <prop key="date_format">yyyy-MM-dd</prop>
                <prop key="time_format">HH:mm:ss</prop>
                <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
                <prop key="number_format">#.##</prop>
            </props>
        </property>
    </bean>
    <!-- JSP定义视图文件解析 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="${web.view.prefix}"/>
        <property name="suffix" value="${web.view.suffix}"/>
        <property name="order" value="0"/>
    </bean>
    
    <!-- 对静态资源文件的访问， 将无法mapping到Controller的path交给default servlet handler处理 -->
    <mvc:default-servlet-handler />
    
    <!-- 静态资源映射 -->
    <mvc:resources mapping="/assets/**" location="/assets/" cache-period="31536000"/>
    
    <!-- 定义无Controller的path<->view直接映射 -->
    <mvc:view-controller path="/" view-name="redirect:${web.view.index}"/>
    
    <!-- 拦截器配置，拦截顺序：先执行后定义的，排在第一位的最后执行。-->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="${adminPath}/**" />
            <mvc:exclude-mapping path="${adminPath}/"/>
            <mvc:exclude-mapping path="${adminPath}/login"/>
            <mvc:exclude-mapping path="${adminPath}/sys/menu/tree"/>
            <mvc:exclude-mapping path="${adminPath}/sys/menu/treeData"/>
            <mvc:exclude-mapping path="${adminPath}/oa/oaNotify/self/count"/>
            <bean class="com.ejweb.core.filter.LogInterceptor" />
        </mvc:interceptor>
        <!-- 手机视图拦截器 -->
        <mvc:interceptor>
            <mvc:mapping path="/**" />
            <bean class="com.ejweb.core.filter.MobileInterceptor" />
        </mvc:interceptor>
    </mvc:interceptors>
    
    <!-- 支持Shiro对Controller的方法级AOP安全控制 begin-->
    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
        <property name="proxyTargetClass" value="true" />
    </bean>
    
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="org.apache.shiro.authz.UnauthorizedException">error/403</prop>
                <prop key="java.lang.Throwable">error/500</prop>
            </props>
            </property>
    </bean>
    <!-- 支持Shiro对Controller的方法级AOP安全控制 end -->
    
    <!-- 上传文件拦截，设置最大上传文件大小   10M=10*1024*1024(B)=10485760 bytes -->  
    <!--<bean id="multipartResolver" class="com.ejweb.core.filter.BaiduCommonsMultipartResolver">
        <property name="maxUploadSize" value="${web.maxUploadSize}" />  
    </bean>-->
    
</beans>