<?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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="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">
<!--解决返回json数据乱码问题-->
<bean id="stringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<mvc:annotation-driven>
<mvc:message-converters>
<ref bean="stringHttpMessageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
<!--注解驱动-->
<mvc:annotation-driven validator="abingValidation"/>
<!-- 注册组件扫描器 -->
<context:component-scan base-package="com.abing.*"/>
<!--注册拦截器-->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.abing.interceptor.MyInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
<!--注册multipartResolver,由DispatcherServlet来负责调用-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--设置字符编码防止文件名乱码-->
<property name="defaultEncoding" value="utf-8"/>
<!--设置上传文件的总大小,单位是字节b-->
<property name="maxUploadSize" value="1048576"/>
<!--设置单个上传文件的大小,单位是字节b-->
<property name="maxUploadSizePerFile" value="1048576"/>
<!--设置内存缓冲区的大小,当超过该值的时候会写入到临时目录-->
<property name="maxInMemorySize" value="1048576"/>
<!--设置临时目录-->
<property name="uploadTempDir" value="tempupload"/>
<!--默认是false,如果设置为true的话,不会将文件路径去除,在IE浏览器下上传时会将路径名也作为文件名上传:D:\image\monkey.png-->
<property name="preserveFilename" value="false"/>
<!--是否使用懒加载,默认是false-->
<property name="resolveLazily" value="true"/>
</bean>
<!--注册Hibernate validation-->
<bean id="abingValidation" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
<property name="providerClass" value="org.hibernate.validator.HibernateValidator"/>
</bean>
<!--解决静态资源无法访问的问题-->
<mvc:resources mapping="/images/**" location="/images/" />
<!-- 视图解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<!--注册自定义异常处理器-->
<bean class="com.abing.error.MyExceptionResolver"/>
</beans>