1. 程式人生 > >Springmvc 中org.springframework.http.converter.json.MappingJackson2HttpMessageConverter依賴jackson包

Springmvc 中org.springframework.http.converter.json.MappingJackson2HttpMessageConverter依賴jackson包

otf dha 配置 beans framework 依賴包 ans cep tpm

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包