Spring 4.3.7抛出java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/util/DefaultIndenter错误

12

在我从Spring 4.3.4迁移到4.3.7时,我在添加Jackson-core依赖后遇到了NoClassDefFound错误。

由此引起的错误: org.springframework.beans.BeanInstantiationException: 无法实例化 [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter]: 构造函数抛出异常; 嵌套异常是 java.lang.NoClassDefFoundError: com / fasterxml / jackson / core / util / DefaultIndenter

我尝试添加jackson-core。

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

依赖关系也有问题,但没有运气。

任何能够阐明此事的人将不胜感激。

谢谢, Vinod


3
DefaultIndenter类是在Jackson 2.5中引入的。也许你项目中的某个其他部分会引入一个早期版本,其中没有这个类。可能是通过某个库的传递依赖关系而来。尝试运行mvn dependency:tree命令并查看输出中是否有早期的Jackson版本。 - Chris Nauroth
给出你的项目依赖快照 - Serhii Povísenko
@Sergey/Chris 我们有一个多模块环境,我们也从其他pom继承依赖项。我发现Jackson-core的依赖版本在所有地方都是相同的。我会清理仓库并向你们更新。感谢你们的快速响应。 - Vinod Sidiginamale
3个回答

1

我遇到了这个问题,使用的是Spring 4.3.22.RELEASE和jackson-databind 2.2.3,只需要升级到2.9.8就可以解决问题。


0
如果有人通过谷歌找到这篇文章,并且您正在使用Spring Boot,以下是解决我的问题的方法。尝试设置您pom文件(即Maven项目)的父级:
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.0.2.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>

这将把 spring-boot-starter 版本设置为 2.0.2,而不是默认的 1.x(至少对我来说是这样)。

根据 Chris Nauroth 的评论,我使用了 mvn dependency:tree 命令,并发现 Spring Boot 1.x 版本使用了 Jackson 2.4.x 版本,而 spring-boot-starter 2.x 版本使用了 Jackson 2.5 或更高版本。


0

这对我有用!

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.0.2.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接