<?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/mvc http://www.springframework.org/schema/mvc/spring-mvc-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">

	<!-- 自动扫描且只扫描@Controller -->
	<context:component-scan base-package="com.yihu.wlyy" 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>

    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
    <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>

    <!-- Enables swagger ui-->
    <mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
    <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>

    <!-- Include a swagger configuration-->
    <bean name="applicationSwaggerConfig" class="com.yihu.wlyy.web.swagger.SwaggerConfig"/>

	<mvc:annotation-driven>
		<mvc:message-converters register-defaults="true">
			<!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
			<bean class="org.springframework.http.converter.StringHttpMessageConverter">
		    	<constructor-arg value="UTF-8" />
			</bean>
			<!-- 将Jackson2HttpMessageConverter的默认格式化输出设为true -->
			<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
                <property name="prettyPrint" value="true"/>
            </bean>			
  		</mvc:message-converters>
	</mvc:annotation-driven>
	
	<!-- 定义JSP文件的位置 --> 
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/"/>
		<property name="suffix" value=".jsp"/>
	</bean>
	
			
	<!-- 容器默认的DefaultServletHandler处理 所有静态内容与无RequestMapping处理的URL-->	
	<mvc:default-servlet-handler/>
	
	<!-- 定义无需Controller的url<->view直接映射 -->
	<mvc:view-controller path="/" view-name="redirect:/index"/>
	
	<!-- 将Controller抛出的异常转到特定View, 保持SiteMesh的装饰效果 -->
	<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">  
		<property name="exceptionMappings">  
			<props>  
				<prop key="java.lang.Throwable">error/500</prop>
            </props>  
		</property>  
    </bean>
    
    <!-- 文件上传配置 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding">
			<value>UTF-8</value>
		</property>
		<property name="maxUploadSize">
			<!-- 上传文件大小限制为31M，31*1024*1024 -->
			<value>32505856</value>
		</property>
		<property name="maxInMemorySize">
			<value>4096</value>
		</property>
	</bean>
	
	<mvc:interceptors>
		<mvc:interceptor>
	        <mvc:mapping path="/patient/**"/>
	        <bean class="com.yihu.wlyy.interceptors.PatientInterceptor"/>
	    </mvc:interceptor>
	    <mvc:interceptor>
	        <mvc:mapping path="/doctor/**"/>
	        <bean class="com.yihu.wlyy.interceptors.DoctorInterceptor"/>
	    </mvc:interceptor>
	    <mvc:interceptor>
	        <mvc:mapping path="/user/**"/>
	        <bean class="com.yihu.wlyy.interceptors.UserInterceptor"/>
	    </mvc:interceptor>
	</mvc:interceptors>
    
</beans>
