<? 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/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.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
< mvc:annotation-driven />
<!-- 将无法mapping到Controller的path交给default servlet handler处理 -->
< mvc:default-servlet-handler />
< context:component-scan base-package = "com.mynote.*"
use-default-filters = "false" >
< context:include-filter type = "annotation"
expression = "org.springframework.stereotype.Controller" />
<!--
shiro方法拦截需求
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" />
-->
</ context:component-scan >
< mvc:interceptors >
<!-- 多个拦截器,顺序执行 -->
< mvc:interceptor >
< mvc:mapping path = "/**" /> <!-- 如果不配置或/*,将拦截所有的Controller -->
< bean class = "com.base.modules.intercepter.SecurityIntercepter" ></ bean >
</ mvc:interceptor >
</ mvc:interceptors >
< bean
class = "org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"
p:prefix = "/" p:suffix = ".ftl" >
< property name = "cache" value = "false" />
< property name = "viewClass"
value = "org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
< property name = "contentType" value = "text/html;charset=UTF-8" ></ property >
< property name = "exposeRequestAttributes" value = "true" />
< property name = "exposeSessionAttributes" value = "true" />
< property name = "exposeSpringMacroHelpers" value = "true" />
< property name = "requestContextAttribute" value = "base" ></ property >
< property name = "order" value = "0" ></ property >
</ bean >
< bean id = "multipartResolver"
class = "org.springframework.web.multipart.commons.CommonsMultipartResolver"
p:defaultEncoding = "UTF-8" />
< bean id = "IndexContentListTag"
class = "com.mynote.tag.IndexContentListTag" >
</ bean >
< bean id = "BKIndexContentListTag"
class = "com.mynote.tag.BKIndexContentListTag" >
</ bean >
< bean id = "contentTag" class = "com.mynote.tag.ContentTag" ></ bean >
< bean id = "HotBlogContentTag"
class = "com.mynote.tag.HotBlogContentTag" >
</ bean >
< bean id = "freemarkerConfig"
class = "org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer" >
< property name = "templateLoaderPath" value = "/templates/" />
< property name = "defaultEncoding" value = "UTF-8" />
< property name = "freemarkerVariables" >
< map >
< entry key = "indexContent"
value-ref = "IndexContentListTag" >
</ entry >
< entry key = "bkContent"
value-ref = "BKIndexContentListTag" >
</ entry >
< entry key = "blogContent" value-ref = "contentTag" ></ entry >
< entry key = "hotContent" value-ref = "HotBlogContentTag" ></ entry >
</ map >
</ property >
< property name = "freemarkerSettings" >
< props >
< prop key = "tag_syntax" >auto_detect</ prop >
< prop key = "template_update_delay" >5</ prop >
< prop key = "defaultEncoding" >UTF-8</ prop >
< prop key = "url_escaping_charset" >UTF-8</ prop >
< prop key = "locale" >zh_CN</ prop >
< prop key = "boolean_format" >true,false</ prop >
< prop key = "datetime_format" >yyyy-MM-dd HH:mm:ss</ prop >
< prop key = "date_format" >yyyy-MM-dd</ prop >
< prop key = "time_format" >HH:mm:ss</ prop >
< prop key = "number_format" >0.######</ prop >
< prop key = "whitespace_stripping" >true</ prop >
<!--空值处理<prop key="classic_compatible">true</prop>-->
<!-- <prop key="auto_import">/ftl/tags/index.ftl as p,/ftl/spring.ftl as s</prop>-->
</ props >
</ property >
</ bean >
< bean
class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
< bean id = "viewResolverCommon"
class = "org.springframework.web.servlet.view.InternalResourceViewResolver" >
< property name = "viewClass"
value = "org.springframework.web.servlet.view.JstlView" />
< property name = "order" value = "1" ></ property >
< property name = "prefix" value = "/WEB-INF/" />
< property name = "suffix" value = ".jsp" ></ property >
</ bean >
< bean
class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
< property name = "messageConverters" >
< list >
<!-- 解析json请求数据,将json转换为java对象-->
< bean
class = "org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
<!-- 解析xml请求数据,将xml转换为java对象-->
< bean
class = "org.springframework.http.converter.xml.MarshallingHttpMessageConverter" >
< constructor-arg >
< bean
class = "org.springframework.oxm.xstream.XStreamMarshaller" >
< property name = "streamDriver" >
< bean
class = "com.thoughtworks.xstream.io.xml.DomDriver" />
</ property >
< property name = "autodetectAnnotations" >
< value >true</ value >
</ property >
<!--可以与xml互换的对象,需要使用XStream的注解,注解的使用方法请参XStream官网-->
<!--
<property name="annotatedClasses">
<list>
<value>com.xxx.XxxxDTO</value>
</list>
</property>
-->
</ bean >
</ constructor-arg >
</ bean >
< bean
class = "org.springframework.http.converter.FormHttpMessageConverter" />
< bean
class = "org.springframework.http.converter.BufferedImageHttpMessageConverter" />
< bean
class = "org.springframework.http.converter.ByteArrayHttpMessageConverter" />
< bean
class = "org.springframework.http.converter.StringHttpMessageConverter" />
<!--
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
-->
<!--可以增加其他数据类型,请参考spring的API-->
</ list >
</ property >
</ bean >
< bean id = "fmXmlEscape"
class = "freemarker.template.utility.XmlEscape" />
< bean
class = "org.springframework.web.servlet.view.ContentNegotiatingViewResolver" >
< property name = "ignoreAcceptHeader" value = "true" />
< property name = "defaultContentType" value = "text/html" />
<!-- 扩展名至mimeType的映射,即 /user.json => application/json -->
< property name = "mediaTypes" >
< map >
< entry key = "html" value = "text/html" />
< entry key = "json" value = "application/json" />
< entry key = "xml" value = "application/xml" />
</ map >
</ property >
<!-- 用于开启 /userinfo/123?format=json 的支持 -->
< property name = "favorParameter" value = "false" />
< property name = "viewResolvers" >
< list >
< bean
class = "org.springframework.web.servlet.view.BeanNameViewResolver" />
</ list >
</ property >
< property name = "defaultViews" >
< list >
<!-- for application/json -->
< bean
class = "org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
<!-- for application/xml -->
< bean
class = "org.springframework.web.servlet.view.xml.MarshallingView" >
< property name = "marshaller" >
< bean
class = "org.springframework.oxm.xstream.XStreamMarshaller" />
</ property >
</ bean >
</ list >
</ property >
</ bean >
< bean id = "localeResolver"
class = "org.springframework.web.servlet.i18n.CookieLocaleResolver" >
< property name = "cookieName" value = "clientlanguage" />
< property name = "cookieMaxAge" value = "-1" />
</ bean >
<!--
<bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor">
<property name="proxyTargetClass" value="true" />
</bean>
<bean
class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"></property>
</bean>
-->
< bean
class = "org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" >
< property name = "exceptionMappings" >
< props >
< prop key = "java.lang.Throwable" >500</ prop >
</ props >
</ property >
< property name = "warnLogCategory" value = "WARN" ></ property >
< property name = "defaultErrorView" value = "500" ></ property >
< property name = "defaultStatusCode" value = "500" ></ property >
< property name = "statusCodes" >
< props >
< prop key = "404" >404</ prop >
< prop key = "500" >500</ prop >
</ props >
</ property >
</ bean >
</ beans >
|