【问题标题】:Spring-Boot 2.1.2 and class com.fasterxml.jackson.annotation.JsonIncludeSpring-Boot 2.1.2 和类 com.fasterxml.jackson.annotation.JsonInclude
【发布时间】:2019-02-07 02:32:42
【问题描述】:

我的 Sprint 启动应用程序没有出现,因为它抱怨缺少类 com.fasterxml.jackson.annotation.JsonInclude$Value,但我有 jackson 库作为依赖项,所以我认为可能会发生一些冲突。

春季日志:

 :: Spring Boot ::        (v2.1.2.RELEASE)

00:22:54.084 [main      ] ERROR ngframework.boot.web.embedded.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class com.fasterxml.jackson.annotation.JsonInclude$Value
00:22:55.063 [main      ] ERROR         org.springframework.boot.SpringApplication - Application run failed

pom.xml(依赖):

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.1.2.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>2.1.2.RELEASE</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.9.4</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.9.4</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.9.4</version>
</dependency>

有没有人遇到过类似的问题? 谢谢

【问题讨论】:

  • 请使用 Spring Boot 父 POM 或 BOM。 Spring boot 针对 BOM 或 POM 避免的特定版本的依赖项进行测试。

标签: spring-boot jackson


【解决方案1】:

jackson-core、jackson-annotations 和 jackson-databind jar 由 spring boot 自动添加。 所以你不需要显式添加它们,除非你想覆盖 spring boot 提供的 jar 的版本。

【讨论】:

  • "除非你想覆盖 spring boot 提供的 jar 版本" - 要覆盖你必须首先 exclude spring-boot 依赖项中的现有版本。
  • @Vusal 或者您可以设置 jackson.version 属性,如果使用父 POM 或将 jackson BOM 放在弹簧靴之前。
  • 您可以从 spring 工具套件依赖项管理选项卡中添加或管理依赖项。如果您提到版本,那么它将自动覆盖弹簧管理的版本
【解决方案2】:

对这两个工件使用以下版本:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.10.0.pr1</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.9.4</version>
</dependency>

此外,如果 maven 构建失败,请将 maven-compiler-plugin 版本更新到最新版本。 Jackson 对 ObjectMapper 类的方法签名进行了一些更改,如果实现则处理相同。

【讨论】:

    猜你喜欢
    • 2019-08-22
    • 1970-01-01
    • 2019-06-08
    • 2016-06-04
    • 2021-12-18
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-10
    相关资源
    最近更新 更多