当classpath上的Jackson 1 JAR时,强制Spring 3.1使用Jackson 2 [英] Force Spring 3.1 to use Jackson 2 when Jackson 1 JARs on the classpath
问题描述
我有一个使用Maven构建的Spring MVC 3.1应用程序,我想使用Jackson 2进行JSON序列化/反序列化.我的pom.xml文件中明确包含Jackson 2.x依赖关系,尽管我的应用程序具有内部使用Jackson 1.9.9的不同依赖关系,而且我无法轻易删除该依赖关系.
I have a Spring MVC 3.1 app built with Maven and I want to use Jackson 2 for JSON serialization/deserialization. I am including Jackson 2.x dependencies explicitly in my pom.xml file, although my app has a different dependency that uses Jackson 1.9.9 internally, and I can't easily remove that dependency.
由于在类路径中同时存在两个Jackson库,因此Spring似乎默认使用1.9.9版的Jackson.
Because of both Jackson libs being present on the classpath, it seems like Spring is defaulting to using Jackson version 1.9.9.
如何强制Spring MVC使用Jackson 2?
How do I force Spring MVC to use Jackson 2?
推荐答案
要实现此目的,我必须调整mvc:annotation驱动的xml配置元素,使其工作如下:
To make this work, I had to adjust my mvc:annotation-driven xml configuration element to work as follows:
<mvc:annotation-driven>
<mvc:message-converters register-defaults="false">
<bean id="jacksonMessageConverter"
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
这篇关于当classpath上的Jackson 1 JAR时,强制Spring 3.1使用Jackson 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!