1.Cannot find class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter] for bean with name 'mappingJacksonHttpMessageConverter' defined in class path resource [config/spring-mvc.xml];
在springmvc.xm把org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
改为
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
[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依赖包
<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>
Spring 3.x.x版本后使用org.springframework.http.converter.json.MappingJacksonHttpMessageConverter
所依赖的jackson包
<dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>1.9.13</version> </dependency>