<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:mvc="http://www.springframework.org/schema/mvc"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xmlns:aop="http://www.springframework.org/schema/aop"
	   xmlns:context="http://www.springframework.org/schema/context"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc.xsd
      http://www.springframework.org/schema/aop  
      http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

	<!-- 扫描注解包路径，多个包用逗号分隔，不填pacakge表示扫描当前ApplicationContext中所有的类 -->
	<context:component-scan base-package="com.gic.haoban.*, com.gic.web.common.*" />

	<!-- 启动对@AspectJ注解的支持 -->
	<aop:aspectj-autoproxy />
	<bean id="multipartResolver"
		  class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="UTF-8"></property>
		<property name="maxUploadSize" value="-1"></property>
	</bean>

	<bean class="com.gic.redis.data.aop.RedisCacheAop" id="redisCacheAop"/>

	<!-- 明确js/css/jpg/gif等静态资源的访问不通过Constroller -->
	<mvc:default-servlet-handler />

	<!-- 启动注解驱动的Spring MVC功能，注册请求url和注解POJO类方法的映射 -->
	<mvc:annotation-driven conversion-service="conversionService">
		<!-- 设置不使用默认的消息转换器 -->
		<mvc:message-converters register-defaults="false">
			<bean class="com.gic.haoban.manage.web.config.LongHttpMessageConverter"/>
			<bean class="com.gic.haoban.common.ext.MappingJackson2HttpMessagePropertyViewConverter"/>
			<bean class="org.springframework.http.converter.StringHttpMessageConverter">
				<property name="supportedMediaTypes">
					<list>
						<value>text/html;charset=UTF-8</value>
                        <value>application/x-www-form-urlencoded;charset=UTF-8</value>
						<!--默认是 iso-8859-1 -->
					</list>
				</property>
			</bean>
			<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
		</mvc:message-converters>
	</mvc:annotation-driven>

	<!-- 启动Spring MVC的注解功能，完成请求和注解POJO的映射 （解决中文乱码） -->
	<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/html;charset=UTF-8</value>
                            <value>application/x-www-form-urlencoded;charset=UTF-8</value>
							<!--默认是 iso-8859-1 -->
						</list>
					</property>
				</bean>
				<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
			</list>
		</property>
	</bean>
	<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
	<property name="converters">
	<set>
	<bean class="com.gic.commons.util.DateConverter"></bean>
	</set>
	</property>
	</bean>

	<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
		<!-- 扩展名至mimeType的映射,即 /user.json => application/json -->
		<property name= "favorPathExtension" value= "true" />
		<!-- 用于开启 /userinfo/123?format=json 的支持 -->
		<property name= "favorParameter" value= "true" />
		<property name= "parameterName" value= "format"/>
		<!-- 是否忽略Accept Header -->
		<property name= "ignoreAcceptHeader" value= "false"/>
		<property name="mediaTypes">
			<value>
				html=text/html
				json=application/json
			</value>
		</property>
		<property name="defaultContentType" value="text/html"/>
	</bean>


	<!-- 视图解析器配置 -->
	<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
	<!-- If no extension matched, use JSP view -->
	<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
		<property name="order" value="0"/>
		<property name="contentNegotiationManager" ref="contentNegotiationManager"/>
		<property name="defaultViews">
			<list>
				<bean class="com.gic.haoban.common.ext.MappingJackson2JsonPropertyView" />
			</list>
		</property>
	</bean>

	<!-- 跨域配置 -->
	<mvc:cors>
		<mvc:mapping path="/**"
					 allowed-headers="*"
					 allowed-origins="*"
					 allowed-methods="GET,POST,PUT,DELETE,OPTIONS"
					 allow-credentials="true"
					 max-age="3600"
		/>
	</mvc:cors>

</beans>