blob: 2e961f65ce16c5988e6b7c9929b4b4c415f11791 (
plain)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
<?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:lang="http://www.springframework.org/schema/lang" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache.xsd">
<!-- 加载配置属性文件 -->
<context:property-placeholder
ignore-unresolvable="true" location="classpath:nis.properties" />
<!-- 静态资源访问,交由default Servlet handler -->
<mvc:default-servlet-handler />
<!-- 静态资源映射 -->
<mvc:resources mapping="/static/**" location="/static/"
cache-period="31536000" />
<mvc:resources mapping="/upload/**" location="/upload/"
cache-period="31536000" />
<!-- <mvc:resources mapping="/swagger/**" location="/swagger/"
cache-period="31536000" /> -->
<!-- 定义无Controller的path<->view直接映射 -->
<mvc:view-controller path="/" view-name="redirect:/nis/index" />
<!-- 启用spring mvc注解 -->
<context:annotation-config />
<!-- 默认注解映射支持 -->
<mvc:annotation-driven />
<!-- <bean class="com.nis.restful.SwaggerConfig" /> -->
<!-- redis 工具类-->
<bean id="redisDao" class="com.nis.util.redis.RedisDao" />
<!-- elasticsearch 工具类 将查询转化为elasticsearch-sql支持的语法-->
<!-- <bean id="elasticsearchSqlDao" class="com.nis.util.elasticsearch.ElasticsearchSqlDao"/> -->
<!-- 定义httpclient连接池 -->
<bean id="httpClientConnectionManager" class="org.apache.http.impl.conn.PoolingHttpClientConnectionManager" destroy-method="close">
<!-- 设置连接总数 -->
<property name="maxTotal" value="${http.pool.maxTotal}"></property>
<!-- 设置每个地址的并发数 -->
<property name="defaultMaxPerRoute" value="${http.pool.defaultMaxPerRoute}"></property>
</bean>
<!-- 定义 HttpClient工厂,这里使用HttpClientBuilder构建-->
<bean id="httpClientBuilder" class="org.apache.http.impl.client.HttpClientBuilder" factory-method="create">
<property name="connectionManager" ref="httpClientConnectionManager"></property>
</bean>
<!-- 得到httpClient的实例 -->
<bean id="httpClient" factory-bean="httpClientBuilder" factory-method="build"/>
<!-- 定期清理无效的连接 -->
<bean class="com.nis.util.httpclient.IdleConnectionEvictor" destroy-method="shutdown">
<constructor-arg index="0" ref="httpClientConnectionManager" />
<!-- 间隔一分钟清理一次 -->
<constructor-arg index="1" value="60000" />
</bean>
<!-- 定义requestConfig的工厂 -->
<bean id="requestConfigBuilder" class="org.apache.http.client.config.RequestConfig.Builder">
<!-- 从连接池中获取到连接的最长时间 -->
<property name="connectionRequestTimeout" value="${http.request.connectionRequestTimeout}"/>
<!-- 创建连接的最长时间 -->
<property name="connectTimeout" value="${http.request.connectTimeout}"/>
<!-- 数据传输的最长时间 -->
<property name="socketTimeout" value="${http.request.socketTimeout}"/>
<!-- 提交请求前测试连接是否可用 -->
<property name="staleConnectionCheckEnabled" value="${http.request.staleConnectionCheckEnabled}"/>
</bean>
<!-- 得到requestConfig实例 -->
<bean id="requestConfig" factory-bean="requestConfigBuilder" factory-method="build" />
<!--事务控制驱动注解,发现注解@Transactional 时,找transactionManager事务管理器 -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- autodetection of such annotated controllers -->
<context:component-scan base-package="com.nis.web"></context:component-scan>
<context:component-scan base-package="com.nis.restful"></context:component-scan>
<!-- 默认的注解映射的支持,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping -->
<mvc:annotation-driven
content-negotiation-manager="contentNegotiationManager">
<mvc:message-converters register-defaults="true">
<!-- 将StringHttpMessageConverter的默认编码设为UTF-8 -->
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" />
</bean>
<!-- 将Jackson2HttpMessageConverter的默认格式化输出为false -->
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>application/json;charset=UTF-8</value>
</list>
</property>
<property name="prettyPrint" value="false" />
<property name="objectMapper">
<bean class="com.nis.util.JsonMapper"></bean>
</property>
</bean>
<!-- 使用XML格式输出数据 -->
<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.StaxDriver" />
</property>
<property name="annotatedClasses">
<list>
<value>com.nis.domain.BaseEntity</value>
<value>com.nis.supcan.TreeList</value>
<value>com.nis.supcan.Col</value>
<value>com.nis.supcan.Group</value>
</list>
</property>
</bean>
</constructor-arg>
<property name="supportedMediaTypes" value="application/xml"></property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- REST中根据URL后缀自动判定Content-Type及相应的View -->
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="ignoreAcceptHeader" value="true" />
<property name="favorPathExtension" value="true" />
</bean>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/nis/**" />
<mvc:exclude-mapping path="/nis/" />
<mvc:exclude-mapping path="/nis/login" />
<mvc:exclude-mapping path="/nis/sys/index" />
<mvc:exclude-mapping path="/nis/sys/menu/tree" />
<mvc:exclude-mapping path="/nis/sys/menu/treeData" />
<mvc:exclude-mapping path="/nis/sys/user/getToDoTaskNum" />
<mvc:exclude-mapping path="/nis/sys/user/toDoTask" />
<bean class="com.nis.interceptor.LogInterceptor" />
</mvc:interceptor>
<!-- 数据源拦截器,该拦截路径下使用数据源B -->
<mvc:interceptor>
<mvc:mapping path="/service/cfg/**" />
<bean class="com.nis.interceptor.DataSourceBInterceptor"></bean>
</mvc:interceptor>
<!-- 数据源拦截器,该拦截路径下使用数据源C -->
<mvc:interceptor>
<mvc:mapping path="/service/log/**" />
<bean class="com.nis.interceptor.DataSourceCInterceptor"></bean>
</mvc:interceptor>
<!-- 数据源拦截器,该拦截路径下使用数据源D,后期会删除 -->
<mvc:interceptor>
<mvc:mapping path="/service/test/**" />
<bean class="com.nis.interceptor.DataSourceDInterceptor"></bean>
</mvc:interceptor>
<!-- 数据源拦截器,该拦截路径下使用数据源E -->
<mvc:interceptor>
<mvc:mapping path="/service/jk/**" />
<bean class="com.nis.interceptor.DataSourceEInterceptor"></bean>
</mvc:interceptor>
</mvc:interceptors>
<!-- 视图文件解析 -->
<bean id="internalResourceViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
<property name="viewNames" value="jsp/*"></property>
<property name="order" value="1"></property>
</bean>
<bean id="urlBaseViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
<property name="order" value="2"></property>
</bean>
<!-- 支持Shiro对Controller的方法级AOP安全控制 begin -->
<bean
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"
depends-on="lifecycleBeanPostProcessor">
<property name="proxyTargetClass" value="true" />
</bean>
<bean id="annotationMethodHandlerExceptionResolver"
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
<property name="order" value="0" />
</bean>
<!-- <bean id="RestServiceExceptionHandler" class="com.nis.restful.AppExceptionHandler">
<property name="order" value="1" />
<property name="errorResolver">
<bean class="com.nis.restful.DefaultRestErrorResolver">
<property name="exceptionMappingDefinitions">
<map>
<entry key="com.nis.restful.RestServiceException" value="404" />
<entry key="Throwable" value="500" />
</map>
</property>
</bean>
</property>
</bean>
-->
<bean
class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.apache.shiro.authz.UnauthorizedException">error/403</prop>
<prop key="java.lang.Throwable">error/500</prop>
</props>
</property>
</bean>
<!-- 支持Shiro对Controller的方法级AOP安全控制 end -->
<!-- 上传文件拦截,设置最大文件大小10m=10*1024*1024(B)=10485760 bytes -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="10485760"></property>
<!--<property name="maxInMemorySize" value="1000"></property> -->
</bean>
</beans>
|