SpringMvc4.2.4+jackson2.7所引出的问题

在搭后台框架,由于是从零开始搭,所以准备所有的jar都用最新的于是springmvc选择了4.2.4,jsckson选择了2.7。当项目后台返回Model对象时,我前端其实想直接得到model的json数据,但是不如人愿,报了如下的错误:

SEVERE: Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception 
java.lang.NoSuchMethodError: org.codehaus.jackson.map.type.TypeFactory.type(Ljava/lang/reflect/Type;)Lorg/codehaus/jackson/type/JavaType;
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.getJavaType(MappingJacksonHttpMessageConverter.java:114)
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.canRead(MappingJacksonHttpMessageConverter.java:91)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.readWithMessageConverters(HandlerMethodInvoker.java:618)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestBody(HandlerMethodInvoker.java:587)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:336)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:169)
at 

 由于没想到是版本的问题,考虑了好久,后来经好多网站查询才得知是jackson2.7不兼容最新的springmvc4.2.4,官网描述:

Work on Jackson 2.7 started in August 2015 and completed in early January 2016. We need to revise our type variable exposure (SPR-13728) for proper Jackson 2.7 support in Spring Framework 4.3 and should also evaluate other changes that are worth adapting to.

 pom.xml(jackson改为了2.6.5)

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

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.6.5</version>
</dependency>

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

 花了整整一天的时间,特此这么晚记录一下,也希望分享给大家,避免走许多弯路。

你可能感兴趣的:(spring,mvc,Jackson)