<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <!-- 静态资源映射 --> <mvc:resources mapping="/static/**" location="/static/" cache-period="172800"/> <!-- 注册mapping,class信息等... --> <mvc:annotation-driven /> <!-- 开启aop --> <aop:aspectj-autoproxy /> <!-- 扫描annotation --> <context:component-scan base-package="com.easilycms.blog" /> <!-- 配置拦截器 --> <mvc:interceptors> <bean class="org.springframework.web.servlet.mvc.WebContentInterceptor"> <property name="cacheSeconds" value="0" /> <property name="useExpiresHeader" value="true" /> <property name="useCacheControlHeader" value="true" /> <property name="useCacheControlNoStore" value="true" /> <property name="alwaysUseFullPath" value="true" /> </bean> </mvc:interceptors> <!-- 多视图解析 .json .xml --> <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="order" value="1" /> <!-- 用于开启 /userinfo/123?format=json 的支持 默认是true --> <property name="favorParameter" value="false" /> <!-- 用于关闭 /userinfo/123.json 的支持 默认是true --> <property name="favorPathExtension" value="true" /> <!-- 设置为true以忽略对Accept Header的支持 --> <property name="ignoreAcceptHeader" value="true" /> <!-- 在没有扩展名时即: "/user/1" 时的默认展现形式 --> <property name="defaultContentType" value="text/html" /> <!-- 扩展名至mimeType的映射,即 /user.json => application/json --> <property name="mediaTypes"> <map> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </map> </property> <property name="defaultViews"> <list> <ref bean="jsonView" /> <ref bean="xmlViewer" /> </list> </property> </bean> <!-- 设置freeMarker的配置文件路径 --> <bean id="freemarkerConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="location" value="classpath:freemarker.properties" /> </bean> <!-- 配置freeMarker的模板路径 --> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="freemarkerSettings" ref="freemarkerConfiguration" /> <property name="templateLoaderPath"> <value>/</value> </property> <property name="freemarkerVariables"> <map> <entry key="xml_escape" value-ref="fmXmlEscape" /> </map> </property> </bean> <bean id="freeMarkerView" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="order" value="2" /> <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /> <property name="prefix" value="WEB-INF/ftl/pages/" /> <property name="suffix" value=".ftl" /> <property name="contentType" value="text/html; charset=utf-8" /> </bean> <bean name="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"> <property name="encoding"> <value type="org.codehaus.jackson.JsonEncoding">UTF8</value> </property> <property name="extractValueFromSingleKeyModel" value="true"></property> <property name="contentType" value="application/json;charset=UTF-8" /> </bean> <bean id="xmlViewer" class="org.springframework.web.servlet.view.xml.MarshallingView"> <constructor-arg> <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <property name="classesToBeBound"> <list> </list> </property> </bean> </constructor-arg> <property name="contentType" value="application/xml;charset=UTF-8" /> </bean> <!-- 文件上传 --> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!--1024**1024*5即5M--> <property name="maxUploadSize" value="5242880"/> </bean> <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" /> </beans>