<?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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	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/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd   
                            http://www.springframework.org/schema/mvc    
                            http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
	<!-- 自动扫描该包，使SpringMVC认为包下用了@controller注解的类是控制器 -->
	<!-- 多包扫描测试 -->
	<context:component-scan base-package="cn.netbuffer.ssmbootstrap_table.controller,com.other.**" 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.RestController" />
        <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
    </context:component-scan>

	<bean id="logBeanPocessor"
		class="cn.netbuffer.ssmbootstrap_table.util.TestBeanPostProcessor"
		lazy-init="false" />

	<!-- fastjson配置 -->
	<bean id="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig">
		<!-- Default charset -->
		<property name="charset" value="UTF-8" />
		<!-- Default dateFormat -->
		<property name="dateFormat" value="yyyy-MM-dd HH:mm:ss" />
		<!--fastjson空值处理:https://github.com/alibaba/fastjson/wiki/WriteNull_cn-->
		<property name="serializerFeatures">
			<list>
				<value>BrowserCompatible</value>
				<value>WriteMapNullValue</value>
				<value>WriteNullListAsEmpty</value>
				<value>WriteNullStringAsEmpty</value>
				<value>WriteNullNumberAsZero</value>
				<value>WriteNullBooleanAsFalse</value>
				<value>WriteNonStringKeyAsString</value>
				<value>WriteNonStringValueAsString</value>
			</list>
		</property>
	</bean>
	<!-- fastjsonView -->
	<bean id="fastJsonJsonView" class="com.alibaba.fastjson.support.spring.FastJsonJsonView">
		<property name="fastJsonConfig" ref="fastJsonConfig" />
	</bean>

	<!-- 多视图配置,内容协商视图解析 -->
	<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
		<property name="favorParameter" value="true" />
		<property name="parameterName" value="format" />
		<property name="favorPathExtension" value="true" />
		<property name="ignoreAcceptHeader" value="false" />
		<property name="defaultContentType" value="text/html" />
		<property name="mediaTypes">
			<map>
				<entry key="json" value="application/json" />
				<entry key="xml" value="application/xml" />
				<entry key="xls" value="application/vnd.ms-excel" />
				<entry key="pdf" value="application/pdf" />
			</map>
		</property>
	</bean>
	<bean
		class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="contentNegotiationManager" ref="contentNegotiationManager"/>
 		<property name="defaultViews">
			<list>
				<!-- <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"></bean> -->
				<!-- 使用fastjson视图输出json数据 -->
				<ref bean="fastJsonJsonView" />
				<bean class="org.springframework.web.servlet.view.xml.MarshallingView">
					<constructor-arg>
						<bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
							<property name="classesToBeBound">
								<list>
									<value>cn.netbuffer.ssmbootstrap_table.model.User</value>
								</list>
							</property>
						</bean>
					</constructor-arg>
				</bean>
				<!--  PDF view -->
          		<bean class="cn.netbuffer.ssmbootstrap_table.view.PdfView" />
          		<!--  excel view -->
          		<bean class="cn.netbuffer.ssmbootstrap_table.view.ExcelView" />
			</list>
		</property>
	</bean>
	<!-- 上面没匹配到则会使用这个视图解析器 -->
	<bean
		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/" />
		<property name="suffix" value=".jsp" />
		<property name="viewClass"
			value="org.springframework.web.servlet.view.JstlView" />
	</bean>
	<!-- <bean class="com.wonders.stpt.bid.controller.JXLExcelView"/> -->

	<!-- 启动SpringMVC的注解功能，完成请求和注解POJO的映射,使 Spring MVC 支持 JSR303 validator via 
		@Valid, and also bind your properties file -->
	<mvc:annotation-driven>
		<mvc:message-converters>
			<!-- fastjson常见问题 -->
			<!-- https://github.com/alibaba/fastjson/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98 -->
			<bean
				class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
				<!-- MediaTypes -->
				<property name="supportedMediaTypes">
					<list>
						<value>application/json</value>
					</list>
				</property>
				<!-- FastJsonConfig -->
				<property name="fastJsonConfig" ref="fastJsonConfig" />
			</bean>
		</mvc:message-converters>
		<mvc:async-support default-timeout="5000" task-executor="asyncThreadPool">
			<mvc:callable-interceptors>
				<bean class="cn.netbuffer.ssmbootstrap_table.interceptor.AsyncInterceptor"></bean>
			</mvc:callable-interceptors>
			<mvc:deferred-result-interceptors>
				<bean class="cn.netbuffer.ssmbootstrap_table.interceptor.DefferedAsyncInterceptor"></bean>
			</mvc:deferred-result-interceptors>
		</mvc:async-support>
	</mvc:annotation-driven>
	
	<bean id="asyncThreadPool"
		class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
			<property name="corePoolSize" value="1" />
			<property name="maxPoolSize" value="10" />
			<property name="queueCapacity" value="50" />
			<property name="threadNamePrefix" value="async-" />
			<property name="keepAliveSeconds" value="30" />
	</bean>
	
	<!-- 设定全局的validator -->
	<!-- <mvc:annotation-driven validator="" /> -->
	<!-- 静态资源等，默认行为 使用应用容器默认的servlet来处理静态资源，tomcat等默认的servlet名字是default，
		其它如果不是default名字的需要显示的设置参数,拦截器中如果拦截所有路径的话，那么这里配置的静态资源也会拦截
		需要在拦截器中exclude-mapping来排除静态资源请求
	-->
	<mvc:default-servlet-handler default-servlet-name="default"/>
	<!-- http://blog.csdn.net/tonytfjing/article/details/39207551 -->
	<!-- <mvc:resources mapping="/css/**" location="/css/"/> -->
	
	<mvc:view-controller path="/" view-name="index.html" />
	<!-- <bean name="xStreamMarshallingView" id="xStreamMarshallingView" class="org.springframework.web.servlet.view.xml.MarshallingView"> 
		<property name="marshaller"> <bean class="org.springframework.oxm.xstream.XStreamMarshaller"> 
		<property name="autodetectAnnotations" value="true" /> <property name="aliases"> 
		<map> Account这个类的别名就变成了myBeans，那么转换后的xml中就是myBeans <entry key="u" value="User"
		/> </map> </property> 基本属性别名 <property name="fieldAliases"> <map> Account中的brithday这个属性 
		<entry key="User.age" value="年龄" />
		</map> </property> </bean> </property> </bean> -->
	<!-- 配置文件上传，如果没有使用文件上传可以不用配置，当然如果不配，那么配置文件中也不必引入上传组件包 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<!-- 默认编码 -->
		<property name="defaultEncoding" value="utf-8" />
		<!-- 文件大小最大值 -->
		<property name="maxUploadSize" value="10485760000" />
		<!-- 内存中的最大值 -->
		<property name="maxInMemorySize" value="40960" />
	</bean>

	<!-- 全局异常配置,也可通过使用@ControllerAdvice注解的类处理全局异常 -->
	<!-- <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> 
		<property name="exceptionMappings"> <props> <prop key="java.lang.Exception">500</prop> 
		<prop key="java.lang.Throwable">500</prop> <prop key="BindException">500</prop> 
		</props> </property> <property name="statusCodes"> <props> <prop key="500">500</prop> 
		</props> </property> 设置日志输出级别，不定义则默认不输出警告等错误日志信息 <property name="warnLogCategory" 
		value="WARN"></property> 默认错误页面，当找不到上面mappings中指定的异常对应视图时，使用本默认配置 <property 
		name="defaultErrorView" value="500"></property> 默认HTTP状态码 <property name="defaultStatusCode" 
		value="500"></property> </bean> -->

	<!-- bind i18n messages properties，发现ReloadableResourceBundleMessageSource这个配置上不好用，不生效 -->
	<!-- <bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="useCodeAsDefaultMessage" value="false" />
		<property name="defaultEncoding" value="UTF-8" />
		<property name="fallbackToSystemLocale" value="true" />
		<property name="basenames">
			<list>
				<value>classpath*:messages</value>
				<value>classpath*:i18n.messages</value>
			</list>
		</property>
	</bean> -->

	<bean id="validator"
		class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
		<property name="providerClass" value="org.hibernate.validator.HibernateValidator" />
		<property name="validationMessageSource" ref="messageSource" />
	</bean>
	
	<!-- i18n资源 -->
	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
	    <!-- 如果在国际化资源文件中找不到对应代码的信息，就用这个代码作为名称  -->               
	    <property name="useCodeAsDefaultMessage" value="true" />
	    <property name="defaultEncoding" value="UTF-8" />
	    <!-- 国际化信息所在的文件名 -->                     
	    <property name="basenames">
			<list>
				<value>messages</value>
				<value>i18n/messages</value>
			</list>
		</property>
	</bean>
	<!-- AcceptHeaderLocaleResolver、CookieLocaleResolver、SessionLocaleResolver、LocaleChangeInterceptor这几种国际化方式 -->
	<!-- 国际化，采用cookie实现 http://kiritor.github.io/2015/09/11/SpringMVC-i18n/ -->
	<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang"/>
    </bean>
	
	<aop:aspectj-autoproxy proxy-target-class="true"/>
	
	<mvc:interceptors>
	 	<!-- 国际化拦截器 -->
	 	<!-- <ref bean="localeChangeInterceptor"/> -->
		<mvc:interceptor>
			<mvc:mapping path="/**"/>
			<!-- 排除静态资源请求 -->
			<mvc:exclude-mapping path="/css/**"/>
			<bean class="cn.netbuffer.ssmbootstrap_table.interceptor.SpringMVCInterceptor" />
		</mvc:interceptor>
		<!-- token拦截器 -->
		<bean
			class="cn.netbuffer.ssmbootstrap_table.interceptor.TokenInterceptor" />
		<!-- 如果不配置或/*,将拦截所有的Controller 定义在mvc:interceptor下面的表示是对特定的请求才进行拦截的 -->
		<!-- <mvc:interceptor> <mvc:mapping <mvc:mapping path="/**"/> path="/test/number.do" /> <bean class="com.host.app.web.interceptor.LoginInterceptor" 
			/> </mvc:interceptor> -->
	</mvc:interceptors>
	
	<bean name="swagger" class="cn.netbuffer.ssmbootstrap_table.util.SwaggerConfig"></bean>
    <mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
</beans>  