简体   繁体   中英

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:

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. it's not supported anymore; I checked and the new version is available on application class path (I imported spring-web dependency). ( Spring 4 and Rest WS integration )

It seems spring is still looking for the old version of 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?

-- 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').

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):

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM