论坛首页 Java企业应用论坛

Spring3升级Spring4(maven)

浏览 3412 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2017-07-13  
1、升级Spring jar版本3.X-4.X

2、升级spring xmlns 版本由3.X.xsd升级到4.X.xsd

3、多视图org.springframework.http.converter.json.MappingJacksonHttpMessageConverter升级org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
<pre name="code" class="java">
&lt;bean class="com.fasterxml.jackson.databind.ObjectMapper" id="objectMapper"&gt;
&lt;!-- 处理responseBody 里面日期类型 --&gt;
&lt;property name="dateFormat"&gt;
&lt;bean class="java.text.SimpleDateFormat"&gt;
&lt;constructor-arg index="0" type="java.lang.String"
value="yyyy-MM-dd HH:mm:ss" /&gt;
&lt;/bean&gt;
&lt;/property&gt;
&lt;property name="serializationInclusion"&gt;
&lt;value type="com.fasterxml.jackson.annotation.JsonInclude.Include"&gt;NON_EMPTY&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;mvc:annotation-driven&gt;
&lt;mvc:message-converters&gt;
&lt;bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt;
&lt;property name="supportedMediaTypes"&gt;
&lt;list&gt;
&lt;value&gt;application/json;charset=UTF-8&lt;/value&gt;
&lt;/list&gt;
&lt;/property&gt;
&lt;property name="objectMapper"&gt;
&lt;ref bean="objectMapper" /&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;bean class="org.springframework.http.converter.StringHttpMessageConverter"&gt;
&lt;!--避免出现乱码 --&gt;
&lt;constructor-arg value="UTF-8" index="0"&gt;&lt;/constructor-arg&gt;
&lt;property name="supportedMediaTypes"&gt;
&lt;list&gt;
&lt;value&gt;text/plain;charset=UTF-8&lt;/value&gt;
&lt;/list&gt;
&lt;/property&gt;
&lt;/bean&gt;
&lt;/mvc:message-converters&gt;
&lt;/mvc:annotation-driven&gt;
</pre>

4、org.springframework.web.servlet.view.ContentNegotiatingViewResolver属性defaultViews 由org.springframework.web.servlet.view.json.MappingJacksonJsonView变更org.springframework.web.servlet.view.json.MappingJackson2JsonView;
以前属性:
&lt;property name="ignoreAcceptHeader" value="true" /&gt;
&lt;property name="defaultContentType" value="text/html" /&gt;
&lt;property name="mediaTypes"&gt;
&lt;map&gt;
&lt;entry key="json" value="application/json;charset=UTF-8" /&gt;
&lt;entry key="xml" value="application/xml;charset=UTF-8" /&gt;
&lt;/map&gt;
&lt;/property&gt;
&lt;property name="favorParameter" value="false" /&gt;
变更
<pre name="code" class="java">
   &lt;bean id="contentNegotiationManager"  class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean"&gt;
        &lt;property name="favorPathExtension" value="true" /&gt;
        &lt;property name="ignoreAcceptHeader" value="true"/&gt;
        &lt;property name="useJaf" value="false"/&gt;
        &lt;property name="defaultContentType" value="text/html" /&gt;
        &lt;property name="mediaTypes"&gt;
            &lt;map&gt;
                &lt;entry key="html" value="text/html"/&gt;
                &lt;entry key="json" value="application/json;charset=UTF-8" /&gt;
&lt;entry key="xml" value="application/xml;charset=UTF-8" /&gt;
           &lt;/map&gt;
        &lt;/property&gt;
    &lt;/bean&gt;


&lt;bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
        &lt;property name="contentNegotiationManager" ref="contentNegotiationManager"/&gt;
&lt;property name="viewResolvers"&gt;
.................................
</pre>

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics