Skip to content

Instantly share code, notes, and snippets.

@longforfreedom
Created December 18, 2013 04:07
Show Gist options
  • Save longforfreedom/8017136 to your computer and use it in GitHub Desktop.
Save longforfreedom/8017136 to your computer and use it in GitHub Desktop.
<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/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">
<context:property-placeholder location="classpath:resources.properties"/>
<!-- 开启controller注解支持 -->
<!-- 注意事项请参考:http://jinnianshilongnian.iteye.com/blog/1762632 -->
<context:component-scan base-package="com.sishuok.es.**.web.controller" 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:component-scan>
<!-- 会自动注册了validator ConversionService -->
<mvc:annotation-driven
validator="validator"
conversion-service="conversionService"
content-negotiation-manager="contentNegotiationManager"
enable-matrix-variables="true"
>
<!--enableMatrixVariables="true">-->
<!-- 异步支持 默认30秒超时 -->
<mvc:async-support default-timeout="30000" task-executor="executor"/>
<mvc:message-converters register-defaults="true">
<!-- StringHttpMessageConverter编码为UTF-8,防止乱码 -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8"/>
<property name = "supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="text"/>
<constructor-arg index="1" value="plain"/>
<constructor-arg index="2" value="UTF-8"/>
</bean>
<bean class="org.springframework.http.MediaType">
<constructor-arg index="0" value="*"/>
<constructor-arg index="1" value="*"/>
<constructor-arg index="2" value="UTF-8"/>
</bean>
</list>
</property>
</bean>
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="fastJsonHttpMessageConverter" class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
<!--<property name="serializerFeature">-->
<!--这个地方加上这个功能吧,能自己配置一些东西,比如时间的格式化,null输出""等等-->
<!--</property>-->
</bean>
</mvc:message-converters>
<mvc:argument-resolvers>
<bean class="com.sishuok.es.common.web.bind.method.annotation.PageableMethodArgumentResolver"/>
<bean class="com.sishuok.es.common.web.bind.method.annotation.SearchableMethodArgumentResolver"/>
<bean class="com.sishuok.es.common.web.bind.method.annotation.FormModelMethodArgumentResolver"/>
<bean class="com.sishuok.es.sys.user.web.bind.method.CurrentUserMethodArgumentResolver"/>
</mvc:argument-resolvers>
</mvc:annotation-driven>
<mvc:view-controller path="/" view-name="redirect:/admin/index"/>
<!-- 当在web.xml 中 DispatcherServlet使用 <url-pattern>/</url-pattern> 映射时,能映射静态资源 -->
<mvc:default-servlet-handler/>
<!-- 静态资源映射 -->
<mvc:resources mapping="/static/**" location="/WEB-INF/static/"/>
<!-- 拦截器设置 -->
<mvc:interceptors>
<bean class="org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor">
<constructor-arg ref="conversionService"/>
</bean>
<bean class="com.sishuok.es.common.web.interceptor.SetCommonDataInterceptor">
<property name="excludeUrlPatterns">
<value>
/admin/polling
</value>
</property>
</bean>
<mvc:interceptor>
<mvc:mapping path="/admin/**" />
<mvc:mapping path="/office/**" />
<mvc:exclude-mapping path="/admin/polling"/>
<bean class="org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor"/>
</mvc:interceptor>
<!--<mvc:interceptor>-->
<!--<mvc:mapping path="/**"/>-->
<!--<bean class="cn.javass.test.interceptor.TestInterceptor"/>-->
<!--</mvc:interceptor>-->
</mvc:interceptors>
<!-- 内容协商管理器 -->
<!--1、首先检查路径扩展名(如my.pdf);2、其次检查Parameter(如my?format=pdf);3、检查Accept Header-->
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<!-- 扩展名至mimeType的映射,即 /user.json => application/json -->
<property name="favorPathExtension" value="true"/>
<!-- 用于开启 /userinfo/123?format=json 的支持 -->
<property name="favorParameter" value="true"/>
<property name="parameterName" value="format"/>
<!-- 是否忽略Accept Header -->
<property name="ignoreAcceptHeader" value="false"/>
<property name="mediaTypes"> <!--扩展名到MIME的映射;favorPathExtension, favorParameter是true时起作用 -->
<value>
json=application/json
xml=application/xml
html=text/html
</value>
</property>
<!-- 默认的content type -->
<property name="defaultContentType" value="text/html"/>
</bean>
<!-- ========================= VIEW定义 ========================= -->
<!-- 内容协商视图解析器;根据客户端的不同的请求决定不同的 view进行响应, 如 /blog/1.json /blog/1.xml -->
<!-- 会自动根据解析的contentType来决定使用哪个视图解析器(默认使用整个web应用中的viewResolver) -->
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver" p:order="0">
<!-- 内容协商管理器 用于决定media type -->
<property name="contentNegotiationManager" ref="contentNegotiationManager"/>
<!-- 默认视图 放在解析链最后 -->
<property name="defaultViews">
<list>
<!--<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>-->
<bean class="com.alibaba.fastjson.support.spring.FastJsonJsonView" />
<!--<bean class="org.springframework.web.servlet.view.xml.MarshallingView"/>-->
</list>
</property>
</bean>
<!-- 默认的视图解析器 在上边的解析错误时使用 (默认使用html)- -->
<bean id="defaultViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:order="1">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="contentType" value="text/html"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!-- 文件上传相关 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!--one of the properties available;the maximum upload size in bytes 100M-->
<property name="maxUploadSize" value="104857600"/>
</bean>
<!-- 控制器异常处理 -->
<bean id="exceptionHandlerExceptionResolver" class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver">
<property name="contentNegotiationManager" ref="contentNegotiationManager"/>
</bean>
<bean class="com.sishuok.es.extra.exception.web.DefaultExceptionHandler"/>
<import resource="spring-mvc-shiro.xml"/>
<!--<import resource="spring-speed-up.xml"/>-->
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment