<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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"> <!-- 配置处理器映射器,用于扫描注解 --> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> <!-- 配置处理器适配器,用于配置handler到底怎么干活,基于注解 --> <!-- 配置json转换器,消息转换器--> <bean class=" org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="stringHttpMessageConverter"/> <ref bean="jackson2HttpMessageConverter"/> </list> </property> </bean> <!-- 自定义消息转换器,配置编码,防止乱码--> <bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> <value>text/plain;charset=UTF-8</value> </list> </property> </bean> <!-- 配置json转换器--> <bean id="jackson2HttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/> <!-- 配置视图解析器,根据逻辑视图名找到物理视图页面--> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 配置ControllerBean --> <!-- <bean class="com.iweb.controller.User3Controller"/>--> <!-- 开启注解扫描配置了@Controller注解的Bean--> <context:component-scan base-package="com.jzy.controller"/> <!--放行静态资源 /statics/** 代表多级目录--> <mvc:resources location="/statics/" mapping="/statics/**" /> </beans>