Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 659
Andrea Girardi Avatar asked Sep 02 '15 15:09

Andrea Girardi


1 Answers

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>
like image 100
Cornel Masson Avatar answered Nov 11 '22 16:11

Cornel Masson