<?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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       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.2.xsd">

    <bean id="sessionService" class="cn.com.qmth.stmms.common.session.service.impl.CookieSessionServiceImpl"/>

    <!-- Handles HTTP GET requests for /static/** by efficiently serving
        up static resources in the ${webappRoot}/static/ directory -->
    <mvc:resources mapping="/resources/**" location="/static/" order="0"/>
    <mvc:resources mapping="/static/**" location="file:${file.store}/" order="0"/>

    <!-- 自动扫描包下的所有类，使其认为spring mvc的控制器 -->
    <context:component-scan base-package="cn.com.qmth.stmms.common.controller,
    				  cn.com.qmth.stmms.common.authorization,
					  cn.com.qmth.stmms.admin,
					  cn.com.qmth.stmms.api,
					  cn.com.qmth.stmms.file,
					  cn.com.qmth.stmms.mark,
					  cn.com.qmth.stmms.monitor,
					  cn.com.qmth.stmms.report,
					  cn.com.qmth.stmms.open,
					  cn.com.qmth.stmms.student">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/>
    </context:component-scan>

    <mvc:annotation-driven/>

    <mvc:interceptors>
        <mvc:interceptor>
       		<mvc:mapping path="/logout"/>
            <mvc:mapping path="/admin/**"/>
            <mvc:mapping path="/mark/**"/>
            <mvc:mapping path="/open/**"/>
            <bean id="sessionInterceptor" class="cn.com.qmth.stmms.common.interceptor.SessionInterceptor"/>
        </mvc:interceptor>
        <mvc:interceptor>
            <mvc:mapping path="/login"/>
            <mvc:mapping path="/admin/**"/>
            <mvc:mapping path="/mark/**"/>
            <mvc:mapping path="/api/**"/>
            <bean id="logInterceptor" class="cn.com.qmth.stmms.common.interceptor.LogInterceptor"/>
        </mvc:interceptor>
        <mvc:interceptor>
            <mvc:mapping path="/admin/**"/>
            <bean id="adminInterceptor" class="cn.com.qmth.stmms.admin.interceptor.AdminInterceptor"/>
        </mvc:interceptor>
        <mvc:interceptor>
            <mvc:mapping path="/admin/sys/**"/>
            <bean id="sysAdminInterceptor" class="cn.com.qmth.stmms.admin.interceptor.SysAdminInterceptor"/>
        </mvc:interceptor>
        <mvc:interceptor>
            <mvc:mapping path="/mark/**"/>
            <bean id="markInterceptor" class="cn.com.qmth.stmms.mark.interceptor.MarkInterceptor"/>
        </mvc:interceptor>
        <mvc:interceptor>
            <mvc:mapping path="/open/**"/>
            <mvc:exclude-mapping path="/open/marker/login"/>
            <mvc:exclude-mapping path="/open/error"/>
            <bean id="openInterceptor" class="cn.com.qmth.stmms.open.interceptor.OpenInterceptor"/>
        </mvc:interceptor>
        <mvc:interceptor>
            <mvc:mapping path="/admin/**"/>
            <bean id="methodInterceptor" class="cn.com.qmth.stmms.common.interceptor.MethodInterceptor"/>
        </mvc:interceptor>
        <mvc:interceptor>
            <mvc:mapping path="/api/**"/>
             <mvc:exclude-mapping path="/api/admin/login"/>
            <bean id="apiInterceptor" class="cn.com.qmth.stmms.api.interceptor.ApiInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>

    <!-- <bean
        class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <property name="mediaTypes">
            <map>
                <entry key="atom" value="application/atom+xml" />
                <entry key="html" value="text/html" />
                <entry key="json" value="application/json" />
            </map>
        </property>
        <property name="viewResolvers">
            <list>
                <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
                <bean
                    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                    <property name="prefix" value="/WEB-INF/jsp/" />
                    <property name="suffix" value=".jsp" />
                    <property name="exposedContextBeanNames">
                        <list>
                            <value>properties</value>
                        </list>
                    </property>
                </bean>
            </list>
        </property>
        <property name="defaultViews">
            <list>
                <bean
                    class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
            </list>
        </property>
    </bean> -->

    <!-- 视图文件解析配置 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
        <property name="redirectHttp10Compatible" value="false"/>
        <property name="exposedContextBeanNames">
            <list>
                <value>properties</value>
            </list>
        </property>
    </bean>
    <!-- Mapping exception to the handler view -->
    <!-- <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        to /error.jsp -->
    <!-- <property name="defaultErrorView" value="error"/> <property name="exceptionMappings">
        <props> </props> </property> </bean> -->

    <!-- 配置SpringMVC @ResponseBody和@RequestBody注解 -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
                <ref bean="jsonHttpMessageConverter"/>
            </list>
        </property>
    </bean>

    <bean id="jsonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>application/json;charset=UTF-8</value>
            </list>
        </property>
    </bean>

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!--配置编码格式-->
        <property name="defaultEncoding" value="utf-8"/>
        <!--配置文件上传大小 最大100MB-->
        <property name="maxUploadSize" value="104857600"/>
        <!--配置缓存大小 最大1MB-->
        <property name="maxInMemorySize" value="1048576"/>
    </bean>

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="ignoreResourceNotFound" value="true"/>
        <property name="locations">
            <list>
                <value>/WEB-INF/application.properties</value>
            </list>
        </property>
    </bean>

    <bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="ignoreResourceNotFound" value="true"/>
        <property name="locations">
            <list>
                <value>/WEB-INF/application.properties</value>
            </list>
        </property>
    </bean>

    <!-- 配置国际化 -->
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="defaultEncoding" value="UTF-8"/>
        <property name="basenames" value="/static/i18n/messages"/>
    </bean>
</beans> 