Spring3升级到Spring4时, 运行时出现找不到MappingJacksonHttpMessageConverter的情况

原文:http://www.cnblogs.com/chry/p/6283483.html

 

[org.springframework.web.context.ContextLoader]Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0' 
... ...
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] for bean with name 'org.springframework.http.converter.json.MappingJacksonHttpMessageConverter#2aa148c0' 
... ...
Caused by: java.lang.ClassNotFoundException: org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
    ... ...

 

 

原因是Spring 3.x 和4.X处理JSON的一个类不一样,而这个东西又配置在xml文件中,所以编译时又无法发现

spring3.x是org.springframework.http.converter.json.MappingJacksonHttpMessageConverter

spring4.x是org.springframework.http.converter.json.MappingJackson2HttpMessageConverter

1. 查找替换所有XML中名字

2. 同时加入最新的FastJackson依赖

 

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.8.5</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.8.5</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>2.8.5</version>
            </dependency>

 

posted @ 2017-04-13 10:04  这个名字想了很久~  阅读(17072)  评论(2编辑  收藏  举报