<?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" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- 开启注解驱动,开启后支持@RequestMapping("/user") 注解 --> <mvc:annotation-driven> <mvc:message-converters> <!-- 字符串格式的消息转换器,用于设置响应结果的字符集编码,处理ajax乱码问题 --> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> </bean> <!-- fastjson自带的json消息转换器,用于将对象转换为json格式字符串返回给客户端 --> <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> <property name="features"> <value>WriteDateUseDateFormat</value> </property> </bean> </mvc:message-converters> </mvc:annotation-driven> <!-- 组件扫描,扫描controller 包下的 @Controller 注解,将所有controller纳入spring管理 --> <context:component-scan base-package="cn.shining"/> <!-- 配置视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/pages/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 配置文件解析器 --> <!-- 这个地方的 id="multipartResolver" 是不能变的,因为这个地方spring是根据 id 来查询的--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="5000000000"></property> <property name="defaultEncoding" value="UTF-8"></property> </bean> <mvc:default-servlet-handler/> <import resource="applicationContext.xml"/> </beans>