[英]MappingJacksonHttpMessageConverter not found with Spring4
I migrated my Spring framework from 3.x to 4.2.RELEASE but, when I start the jUnit I'm getting this error: 我将我的Spring框架从3.x迁移到4.2.RELEASE但是,当我启动jUnit时,我收到此错误:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from URL [file:src/test/resources/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/http/converter/json/MappingJacksonHttpMessageConverter
I read on internet from Version 4.1. 我从4.1版开始在互联网上阅读。 it's not supported anymore;
它不再受支持了; I checked and the new version is available on application class path (I imported spring-web dependency).
我检查过,新版本在应用程序类路径上可用(我导入了spring-web依赖项)。 ( Spring 4 and Rest WS integration )
( Spring 4和Rest WS集成 )
It seems spring is still looking for the old version of Converter. 看来春天还在寻找老版本的Converter。 It probably depends on something I've on my application context, but, the question is, how can I "tell to Spring" to use new version?
它可能取决于我在我的应用程序上下文中的一些东西,但问题是,我如何“告诉Spring”使用新版本?
-- UPDATE - 更新
I commented 我评论道
<mvc:annotation-driven />
and it seems to works fine but... why? 它似乎工作正常但是......为什么?
There's a newer version of that class in Spring 4: use org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
(note the '2'). 在Spring 4中有一个更新版本的类:使用
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
(注意'2')。
In my REST servlet's Spring config file I have it configured as follows (I added my custom objectMapper to it, but you can just omit that): 在我的REST servlet的Spring配置文件中,我将它配置如下(我将自定义的objectMapper添加到它,但你可以省略它):
<mvc:annotation-driven>
<mvc:message-converters>
<bean
class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="s3.util.json.CustomJsonMapper" />
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.