spring3 升级Spring4 需要注意的地方
1.修改msgconvert
<!-- 注入fastjson配置类 --> <bean name="fastJsonConfig" class="com.alibaba.fastjson.support.config.FastJsonConfig"> <property name="serializerFeatures"> <list> <value>WriteMapNullValue</value> <value>WriteMapNullValue</value> <value>WriteNullNumberAsZero</value> <value>WriteNullListAsEmpty</value> <value>WriteNullStringAsEmpty</value> <value>WriteNullBooleanAsFalse</value> <value>WriteDateUseDateFormat</value> </list> </property> </bean>
<!-- 配置多请求数据类型,如json xml --> <mvc:annotation-driven conversion-service="conversionService" content-negotiation-manager="contentNegotiationManager"> <mvc:message-converters register-defaults="true"> <bean class="org.springframework.http.converter.FormHttpMessageConverter"/> <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/> <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/xml</value> <value>text/html;charset=UTF-8</value> </list> </property> </bean> <bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg value="UTF-8"/> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> </bean>
<bean id = "mappingJackson2HttpMessageConverter"
class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> </list> </property> <!-- 配置 --> <property name="fastJsonConfig" ref="fastJsonConfig"/> </bean> </mvc:message-converters>
</mvc:annotation-driven>
2.移除asm jar包
3.若在jboss中使用
jboss-deployment-structure 添加
<module name="org.jboss.as.jsf-injection" />
<module name="com.fasterxml.jackson.core.jackson-core"/>
<module name="com.fasterxml.jackson.core.jackson-databind"/>
<module name="com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider"/>
<module name="org.jboss.resteasy.resteasy-jackson2-provider"/>
否则可能出现(即使你引用的jar类包含):
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;
4.freeMarker升级到2.3.23
5. Not Acceptable
修改 contentNegotiationManager 配置
<bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean" > <property name="favorPathExtension" value="false"/> </bean> <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="order" value="0"/> <property name="contentNegotiationManager" ref="contentNegotiationManager"/> <property name="defaultViews"> <list> <bean class="com.alibaba.fastjson.support.spring.FastJsonJsonView"> <property name="charset" value="UTF-8"/> </bean> </list> </property> </bean>
上一篇: vps服务器批量管理 iis7批量管理
下一篇: EF的三种继承模式