<?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:mvc="http://www.springframework.org/schema/mvc"
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/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--开启包的注解扫描 只去扫描springMvc有关的注解,解耦分开管理-->
<context:component-scan base-package="com.yellow" 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.ControllerAdvice"/>
<context:include-filter type="annotation"
expression="org.springframework.web.bind.annotation.ExceptionHandler"/>
</context:component-scan>
<!--配置开放静态资源访问的路径-->
<mvc:resources mapping="/js/**" location="/js/"/>
<!--当SpringMvc无法解析url找到资源时,使用tomcat去寻找资源-->
<mvc:default-servlet-handler/>
<!--配置处理器适配器,注入jackson 可以使用mvc:annotation-driven代替-->
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<!--配置SpringMvc需要的jackson实现的类,当项目使用fastjson,这里就需要修改对应的实现类-->
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</list>
</property>
</bean>
<!--注解驱动扫描,SpringMvc底层会自动自动配置jackjson-->
<!--<mvc:annotation-driven conversion-service="conversionService"/>-->
<!--注解驱动-->
<!--配置StringHttpMessageConverter解决resp响应中文乱码-->
<mvc:annotation-driven conversion-service="conversionService">
<!--配置StringHttpMessageConverter解决resp响应中文乱码-->
<mvc:message-converters>
<!--注入属性utf-8-->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="utf-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<mvc:default-servlet-handler/>
<!--内部视图解析器,View对象会在这里解析拼接上url-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--前缀-->
<property name="prefix" value="/"/>
<!--后缀-->
<property name="suffix" value=".jsp"/>
</bean>
<!--配置拦截器链 执行优先级,从上到下-->
<mvc:interceptors>
<!--拦截器一-->
<mvc:interceptor>
<!--那些路径被拦截 /** 路径及其子路径都会拦截 -->
<mvc:mapping path="/**"/>
<!--那些路径不被拦截 /test1不会被拦截 -->
<mvc:exclude-mapping path="/test1"/>
<!--拦截器全限路径-->
<bean></bean>
</mvc:interceptor>
<!--拦截器二-->
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean></bean>
</mvc:interceptor>
</mvc:interceptors>
<!--自定义date类型转换 需要扫描注解驱动的地方配置conversion-service <mvc:annotation-driven conversion-service="conversionService"/> -->
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
<property name="converters">
<list>
<!--自定义date类型转换类的全限命名-->
<bean class="com.yellow.converter.DateConverter"></bean>
</list>
</property>
</bean>
<!--配置简单异常处理器,SpringMvc提供的-->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<!--默认的异常跳转页面-->
<property name="defaultErrorView" value="/error.jsp"/>
<property name="exceptionMappings">
<!--内部配置map-->
<map>
<entry key="java.lang.NullPointerException" value="/error01.jsp"/>
</map>
</property>
</bean>
<!--需要使用文件上传时,配置文件上传解析器 需要导入对应文件上传的坐标-->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--设置编码-->
<property name="defaultEncoding" value="utf-8"/>
<!--上传文件总大小-->
<property name="maxUploadSize" value="50000"/>
<!--单次上传文件大小-->
<property name="maxUploadSizePerFile" value="10000"/>
</bean>
</beans>