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

	<description>Spring-web MVC配置</description>

	<!-- 对所有类进行扫描，以完成Bean创建和自动依赖注入的功能 -->
	<context:component-scan base-package="com.cloudcross.ssp.web">
		<context:include-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>
	
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="utf-8"></property>
		<property name="maxUploadSize" value="10000000"></property>
	</bean>
	
	<!-- 当请求应用程序首页时，将执行/hello请求，还可以设定成redirect -->
	<mvc:view-controller path="/" view-name="forward:/index" />
	<!-- 对静态资源文件的访问 -->
	<mvc:resources mapping="/favorite.ico" location="/favorite.ico" />
	<mvc:resources mapping="/assets/**" location="/assets/" />
	<mvc:resources mapping="/upload/**" location="/upload/" />
	<mvc:interceptors>
		<bean class="com.cloudcross.ssp.base.web.interceptor.SharedRenderVariableInterceptor"></bean>
	</mvc:interceptors>
	<!-- 这两个类用来启动基于Spring MVC的注解功能，将控制器与方法映射加入到容器中 -->
	<bean
		class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
	<bean
		class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean
					class="org.springframework.http.converter.StringHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/plain;charset=UTF-8</value>
						</list>
					</property>
				</bean>
				<bean
					class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>application/json;charset=UTF-8</value>
						</list>
					</property>
				</bean>
			</list>
		</property>
	</bean>

	<bean id="viewResolver"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
		<property name="cache" value="true" />
		<!-- 模板后缀，指定html页面为模板 -->
		<property name="suffix" value=".ftl" />
		<!-- 使用这个模板类来解析视图 -->
		<property name="viewClass"
			value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
		<property name="exposeSpringMacroHelpers" value="true" />
		<!-- 允许访问请求属性，默认为false -->
		<property name="exposeRequestAttributes" value="true" />
		<!-- 允许访问会话属性，默认为false -->
		<property name="exposeSessionAttributes" value="true" />
		<!-- 页面上下文，类似于request.contextPath -->
		<property name="requestContextAttribute" value="rc" />
		<!-- 模板输出内容编码，此处应与defaultEncoding保持一致 -->
		<property name="contentType" value="text/html;charset=UTF-8" />
	</bean>

	<bean id="blockDirective"
		class="com.cloudcross.ssp.base.utils.freemarker.directive.BlockDirective" />
	<bean id="extendsDirective"
		class="com.cloudcross.ssp.base.utils.freemarker.directive.ExtendsDirective" />
	<bean id="overrideDirective"
		class="com.cloudcross.ssp.base.utils.freemarker.directive.OverrideDirective" />
	<bean id="superDirective"
		class="com.cloudcross.ssp.base.utils.freemarker.directive.SuperDirective" />

	<bean id="freemarkerConfig"
		class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
		<!-- 模板文件所在目录 -->
		<property name="templateLoaderPath" value="/WEB-INF/pages/" />
		<!-- 指定FreeMarker模板文件的编码格式 -->
		<property name="defaultEncoding" value="UTF-8" />
		<!-- FreeMarker属性配置 -->
		<property name="freemarkerSettings">
			<props>
				<!-- 每隔5小时检查模板是否更新，单位为秒 如果不经常更新模板可将更新的延迟时间设定长一点 -->
				<prop key="template_update_delay">1</prop>
				<!-- 指定地区语言环境，我们的语言是中文 -->
				<prop key="locale">zh_CN</prop>
				<prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
				<prop key="date_format">yyyy-MM-dd</prop>
				<prop key="time_format">HH:mm:ss</prop>
				<prop key="number_format">0.##</prop>
				<prop key="auto_import">common/auto/spring.ftl as spring</prop>
			</props>
		</property>
		<property name="freemarkerVariables">
			<map>
				<entry key="extends" value-ref="extendsDirective"></entry>
				<entry key="override" value-ref="overrideDirective"></entry>
				<entry key="block" value-ref="blockDirective"></entry>
				<entry key="super" value-ref="superDirective"></entry>
			</map>
		</property>
	</bean>

	<bean id="messageSource"
		class="org.springframework.context.support.ResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<value>config/i18n/messages</value>
			</list>
		</property>
	</bean>

	<bean id="localeResolver"
		class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
		<property name="cookieName" value="clientlanguage" />
		<property name="cookieMaxAge" value="94608000" />
		<property name="defaultLocale" value="en" />
	</bean>

	<bean id="exceptionResolver"
		class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
		<property name="exceptionMappings">
			<props>
				<prop key="com.cloudcross.ssp.common.error.NotFoundException">errors/404</prop>
				<prop key="com.cloudcross.ssp.common.error.SystemException">errors/500</prop>
				<prop key="com.cloudcross.ssp.common.error.AppException">errors/500</prop>
			</props>
		</property>
		<property name="statusCodes">
			<props>
				<prop key="errors/500">500</prop>
				<prop key="errors/404">404</prop>
			</props>
		</property>
		<!-- 设置日志输出级别，不定义则默认不输出警告等错误日志信息 -->
		<property name="warnLogCategory" value="WARN"></property>
		<!-- 默认错误页面，当找不到上面mappings中指定的异常对应视图时，使用本默认配置 -->
		<property name="defaultErrorView" value="errors/500"></property>
		<property name="defaultStatusCode" value="500"></property>
	</bean>

</beans>