<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:aop="http://www.springframework.org/schema/aop"
	   xmlns:context="http://www.springframework.org/schema/context"
	   xmlns:mvc="http://www.springframework.org/schema/mvc"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:task="http://www.springframework.org/schema/task"
	   xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        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.xsd 
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
		 http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd">

	<!-- 扫描controller（controller层注入） -->
	<context:component-scan base-package="com.cftech">
		<context:include-filter type="annotation"
								expression="org.springframework.stereotype.Controller" />
	</context:component-scan>
	<!-- 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter
		两个bean,是spring MVC为@Controllers分发请求所必须的 -->
	<!-- 指定自己定义的validator -->
	<mvc:annotation-driven validator="validator" />

	<!-- 以下 validator ConversionService 在使用 mvc:annotation-driven 会 自动注册 -->
	<bean id="validator"
		  class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
		<property name="providerClass" value="org.hibernate.validator.HibernateValidator" />
		<!-- 如果不加默认到 使用classpath下的 ValidationMessages.properties -->
		<property name="validationMessageSource" ref="messageSource" />
	</bean>

	<!-- 国际化的消息资源文件（本系统中主要用于显示/错误消息定制） -->
	<bean id="messageSource"
		  class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<!-- 在web环境中一定要定位到classpath 否则默认到当前web应用下找 -->
				<value>classpath:messages</value>
				<value>classpath:org/hibernate/validator/ValidationMessages</value>
			</list>
		</property>
		<property name="useCodeAsDefaultMessage" value="false" />
		<property name="defaultEncoding" value="UTF-8" />
		<property name="cacheSeconds" value="60" />
	</bean>

	<mvc:interceptors>
		<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
		<mvc:interceptor>
			<mvc:mapping path="/a/**" />
			<ref bean="logInterceptor" />
		</mvc:interceptor>
	</mvc:interceptors>

	<bean id="logInterceptor" class="com.cftech.sys.interceptor.LogInterceptor"></bean>

	<mvc:default-servlet-handler />

	<bean id="localeResolver"
		  class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
		<property name="defaultLocale" value="zh_CN" />
	</bean>

	<!-- 支持返回json(避免IE在ajax请求时，返回json出现下载 ) -->
	<bean
			class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<ref bean="mappingJacksonHttpMessageConverter" />
			</list>
		</property>
	</bean>
	<bean id="mappingJacksonHttpMessageConverter"
		  class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
		<property name="supportedMediaTypes">
			<list>
				<value>text/plain;charset=UTF-8</value>
				<value>application/json;charset=UTF-8</value>
			</list>
		</property>
	</bean>
	<!-- 支持返回json -->

	<!-- 对模型视图添加前后缀 -->

	<!-- 定义视图解析器 -->
	<bean id="velocityConfig"
		  class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
		<property name="resourceLoaderPath" value="/WEB-INF/views/" />
		<property name="configLocation" value="classpath:velocity.properties" />
	</bean>
	<bean id="viewResolver"
		  class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
		<property name="suffix" value=".html" />
		<property name="cache" value="false" />
		<property name="contentType" value="text/html;charset=utf-8" />
		<property name="dateToolAttribute" value="date" /><!--日期函数名称 -->
		<property name="numberToolAttribute" value="number" /><!--数字函数名称 -->
		<property name="layoutUrl" value="layout/default.vm" />
		<property name="toolboxConfigLocation" value="/WEB-INF/toolbox.xml" />
	</bean>
	<bean id="multipartResolver" class="com.cftech.core.feature.MyMultipartResolver">
		<property name="excludeUrls" value="FileUpload" />
		<property name="defaultEncoding" value="utf-8"/>
		<property name="maxUploadSize" value="10485760000"/>
		<property name="maxInMemorySize" value="40960"/>
		<!-- url中带有example的http请求就不会被multipartResolver先解析 -->
	</bean>
	<!-- 配置springMVC处理上传文件的信息 -->

	<!-- 启用shrio授权注解拦截方式 -->
	<aop:config proxy-target-class="true"></aop:config>
	<bean
			class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
		<property name="securityManager" ref="securityManager" />
	</bean>

	<task:executor id="executor" pool-size="5" />
	<task:scheduler id="scheduler" pool-size="10" />
	<task:annotation-driven executor="executor" scheduler="scheduler" />

</beans>
