spring-mvc.xml
6.83 KB
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
<?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:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
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-4.3.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd">
<!--对于请求返回字符串时,默认StringHttpMessageConverter,且其默认编码为ISO-8859-1,不会通过上面的MappingJacksonJsonView,因此客服端看到的中文会是乱码 -->
<!--对于请求返回对象时,下面配置的MappingJacksonJsonView来处理,返回sjon串 -->
<bean id="stringHttpMessageConverter"
class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8" />
<property name="supportedMediaTypes">
<list>
<value>application/xml;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
<value>text/plain;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- mvc:annotation-driven 使用默认的 stringHttpMessageConverter,默认的编码为ISO-8859-1,因此需要替换它 -->
<mvc:annotation-driven>
<mvc:message-converters>
<ref bean="stringHttpMessageConverter" />
</mvc:message-converters>
</mvc:annotation-driven>
<context:component-scan base-package="com.b2c.orders.web" />
<context:annotation-config />
<!-- static resources -->
<mvc:resources location="/assets/" mapping="/assets/**"
cache-period="864000" /><!-- 24 * 3600 * 10 -->
<!-- template view -->
<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/vm/" />
<property name="velocityProperties">
<props>
<prop key="input.encoding">UTF-8</prop>
<prop key="output.encoding">UTF-8</prop>
<prop key="contentType">text/html;charset=UTF-8</prop>
<prop key="velocimacro.library">common/macro.vm</prop>
<prop key="file.resource.loader.cache">false</prop>
<prop key="file.resource.loader.modificationCheckInterval">1</prop>
<prop key="velocimacro.library.autoreload">true</prop>
<prop key="eventhandler.referenceinsertion.class">org.apache.velocity.app.event.implement.EscapeHtmlReference
</prop>
<prop key="eventhandler.escape.html.match">/^(?!.*\\$screen_content).*$/</prop>
</props>
</property>
</bean>
<!-- 视图可能用到的工具类 -->
<util:map id="viewTools">
<entry key="webUtils" value-ref="webUtils" />
<entry key="domain" value="${orders.contextPath}" />
<entry key="dateTool">
<bean class="org.apache.velocity.tools.generic.DateTool" />
</entry>
<entry key="numberTool">
<bean class="org.apache.velocity.tools.generic.NumberTool" />
</entry>
<entry key="escape">
<bean class="org.apache.velocity.tools.generic.EscapeTool" />
</entry>
<entry key="math">
<bean class="org.apache.velocity.tools.generic.MathTool" />
</entry>
<entry key="stringUtils">
<bean class="org.apache.commons.lang.StringUtils" />
</entry>
</util:map>
<bean id="velocityViewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
<property name="layoutUrl" value="layout/onlyContent.vm" />
<property name="cache" value="false" />
<property name="suffix" value=".vm" />
<property name="exposeSpringMacroHelpers" value="true" />
<!-- Merge urlBuilderMap to view context for convenience. You can put your
tools which must be thread safe. -->
<property name="contentType" value="text/html;charset=UTF-8" />
<!--toolbox配置文件路径 -->
<property name="attributesMap" ref="viewTools" />
</bean>
<!-- 文件上传 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
</bean>
<bean id="webUtils" class="com.b2c.orders.commons.utils.WebUtils">
<property name="assetsPath" value="${orders.contextPath}/assets" />
<property name="contextPath" value="${orders.contextPath}" />
<property name="staticDomain" value="${project.static.path}" />
</bean>
<bean id="currencyTool" class="com.b2c.orders.commons.utils.CurrencyTool" />
<bean id="contentNegotiationManager"
class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
<property name="ignoreAcceptHeader" value="true" />
<property name="defaultContentType" value="text/html;charset=UTF-8" />
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
</map>
</property>
<property name="favorParameter" value="true" />
</bean>
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="contentNegotiationManager" ref="contentNegotiationManager" />
<property name="viewResolvers">
<list>
<ref bean="velocityViewResolver" />
</list>
</property>
<property name="defaultViews">
<list>
<!-- for application/json MappingJacksonJsonView 默认编码为UTF-8 因此,请求返回对象时,会自动使用此view,使用UTF-8编码将对象转换为json -->
<bean
class="org.springframework.web.servlet.view.json.MappingJackson2JsonView">
</bean>
</list>
</property>
</bean>
<!-- locale related -->
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieName" value="_clientlocale" />
<property name="defaultLocale" value="zh_CN" />
<property name="cookieMaxAge" value="2147483647" />
</bean>
<bean id="conversionService"
class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<list>
<bean class="com.b2c.orders.web.utils.OrderStatusConverter" />
<bean class="com.b2c.orders.web.utils.UserTypeConverter" />
<bean class="com.b2c.orders.web.utils.ActionConverter" />
<bean class="com.b2c.orders.web.utils.OrderDeliveryTypeConverter" />
<bean class="com.b2c.orders.web.utils.PayStatusConverter" />
<bean class="com.b2c.orders.web.utils.PayTypeConverter" />
<bean class="com.b2c.orders.web.utils.DateConverter" />
</list>
</property>
</bean>
<mvc:annotation-driven conversion-service="conversionService" />
</beans>