Springmvc 中org.springframework.http.converter.json.MappingJackson2HttpMessageConverter依赖jackson包(示例代

Posted lonecloud

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Springmvc 中org.springframework.http.converter.json.MappingJackson2HttpMessageConverter依赖jackson包(示例代相关的知识,希望对你有一定的参考价值。

1,问题详情:Spring使用4.3.5.Release版本后

在SpringMvc配置文件中配置json 解析器后出现报错信息

 

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

 

2.原因:

  Spring4.0后jackson依赖包不一样导致

3.解决方案

Spring 4.x.x版本后使用org.springframework.http.converter.json.MappingJackson2HttpMessageConverter所对应的jar

在maven配置jackson依赖包

 1        <dependency>
 2             <groupId>com.fasterxml.jackson.core</groupId>
 3             <artifactId>jackson-core</artifactId>
 4             <version>2.8.5</version>
 5         </dependency>
 6         <dependency>
 7             <groupId>com.fasterxml.jackson.core</groupId>
 8             <artifactId>jackson-databind</artifactId>
 9             <version>2.8.5</version>
10         </dependency>
11         <dependency>
12             <groupId>com.fasterxml.jackson.core</groupId>
13             <artifactId>jackson-annotations</artifactId>
14             <version>2.8.5</version>
15         </dependency>

 Spring 3.x.x版本后使用org.springframework.http.converter.json.MappingJacksonHttpMessageConverter

 所依赖的jackson包

1         <dependency>
2             <groupId>org.codehaus.jackson</groupId>
3             <artifactId>jackson-mapper-asl</artifactId>
4             <version>1.9.13</version>
5         </dependency>

 

以上是关于Springmvc 中org.springframework.http.converter.json.MappingJackson2HttpMessageConverter依赖jackson包(示例代的主要内容,如果未能解决你的问题,请参考以下文章

Sentinel-结合RestTemplate

Spring 框架系列之 JDBC 整合实例

Spring之JDBCTemplate学习

以Java 8 为基准

SpringBoot热启动

Maven使用