Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 4.3.5和Jackson 2.8.7工作不正常_Spring_Jackson - Fatal编程技术网

Spring 4.3.5和Jackson 2.8.7工作不正常

Spring 4.3.5和Jackson 2.8.7工作不正常,spring,jackson,Spring,Jackson,我使用的是springVersion='4.3.5.RELEASE'和jacksonVersion='2.8.7' 但每次都会抛出以下异常: Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;

我使用的是
springVersion='4.3.5.RELEASE'
jacksonVersion='2.8.7'

但每次都会抛出以下异常:

Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.forType(Lcom/fasterxml/jackson/databind/JavaType;)Lcom/fasterxml/jackson/databind/ObjectWriter;
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:278) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:100) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:231) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:203) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81) [spring-web-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:132) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) [spring-webmvc-4.3.5.RELEASE.jar:4.3.5.RELEASE]
    ... 37 more
无法理解它为何抛出此异常。从这个链接得到了帮助,并根据专家的回答将jacksonVersion更改为兼容版本,但我还是遇到了同样的问题

我的gradle文件看起来像:

springVersion           = '4.3.5.RELEASE'
springDataVersion       = '1.10.5.RELEASE'
jacksonVersion          ='2.8.7'

dependencies {

compile "org.springframework:spring-context:${springVersion}"
compile "org.springframework:spring-context-support:${springVersion}"
compile "org.springframework:spring-core:${springVersion}"
compile "org.springframework:spring-web:${springVersion}"
compile "org.springframework:spring-webmvc:${springVersion}"
compile "org.springframework:spring-tx:${springVersion}"
compile "org.springframework:spring-beans:${springVersion}"
compile "org.springframework:spring-aop:${springVersion}"
compile "org.springframework:spring-test:${springVersion}"
compile "org.springframework.data:spring-data-jpa:${springDataVersion}"
compile "org.springframework:spring-orm:${springVersion}"

compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
}

这肯定是一个版本兼容性问题,所以运行时使用的
jackson-databind
版本比您需要的版本旧。 即使您已经更新了依赖项,也可能会被其他内容覆盖;或者,您可能在类路径中有多个JAR(在这种情况下,任意选择一个JAR…当然,它通常是旧的JAR)


我相当确定这是版本问题的原因是JVM链接器发现了问题:正在运行的版本是针对具有该方法的较新版本编译的,但正在加载的版本没有该方法。

run
gradle dependencies
,以确保您没有引入旧版本的Jackson。我们使用的是Spring 4.3.14.RELEASE和Jackson 2.9.2,没有任何问题,但多年来我们不断更新我们的依赖项,从未遇到Spring/Jackson的问题。我检查过,它没有拉旧版本。