-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
spring-mvc.xml
176 lines (153 loc) · 8.61 KB
/
spring-mvc.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<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>