Spring boot应用失败,Jackson2ObjectMapperBuilder。可见性不存在

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring boot应用失败,Jackson2ObjectMapperBuilder。可见性不存在相关的知识,希望对你有一定的参考价值。

在我的Spring Boot应用程序中,我有很少的依赖项:

implementation "org.springframework.boot:spring-boot-starter:$springBootVersion"
testImplementation "org.springframework.boot:spring-boot-starter-test:$springBootVersion"

应用程序无法启动:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    java.lang.invoke.MethodHandleNatives.resolve(Native Method)

The following method did not exist:

    org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.visibility(Lcom/fasterxml/jackson/annotation/PropertyAccessor;Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder;

The method's class, org.springframework.http.converter.json.Jackson2ObjectMapperBuilder, is available from the following locations:

    jar:file:/Users/me/.gradle/caches/modules-2/files-2.1/org.springframework/spring-web/4.3.25.RELEASE/76d29c076153e09961c8e6fd9b2d5c50bb80b902/spring-web-4.3.25.RELEASE.jar!/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.class

It was loaded from the following location:

    file:/Users/me/.gradle/caches/modules-2/files-2.1/org.springframework/spring-web/4.3.25.RELEASE/76d29c076153e09961c8e6fd9b2d5c50bb80b902/spring-web-4.3.25.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.http.converter.json.Jackson2ObjectMapperBuilder

Disconnected from the target VM, address: '127.0.0.1:57370', transport: 'socket'

Process finished with exit code 1

springBootVersion为2.2.6.RELEASE

答案

spring-boot-starter依赖项似乎不包括所需类所在的spring-web。将implementation "org.springframework.boot:spring-boot-starter-web:$springBootVersion"添加到您的Gradle文件中,然后重试。

以上是关于Spring boot应用失败,Jackson2ObjectMapperBuilder。可见性不存在的主要内容,如果未能解决你的问题,请参考以下文章

Tomcat中的spring-boot应用程序战争部署,现有的spring web应用程序失败

如何让 Spring Boot 应用程序在 tomcat 失败时退出

Spring Boot 应用程序失败,退出代码为 0

Spring Boot 应用程序在 mockmvc 测试中失败

Spring Boot应用程序失败-错误java包不存在

在 Spring Boot 应用程序中使用嵌入式 MongoDb 以及 MongoTemplate 失败