【踩坑日记】jackson依赖导入报错找不到类
·
前言
- 公司的微服务框架代码里面集成了一些maven依赖,jackson-databind的版本是2.9.8
- 之前在使用的时候,直接在pom文件里改成了2.9.9版本,覆盖了原有框架里的低版本
- 现在,想换成2.13.1版本,在pom文件里将版本改高,项目无法启动,报错
<!-- 公司框架里的2.9.10依赖 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.10</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.10</version>
</dependency>
<!-- 原本pom文件里的2.9.9依赖,此处应该是需求,加了jackson-core依赖 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.9</version>
</dependency>
<!-- 现在修改之后的2.13.1依赖 单纯把jackson-core和jackson-databind改成了2.13.1版本 -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.13.1</version>
</dependency>
<!-- 报错 -->
Caused by: java.lang.ClassNotFoundException Create breakpoint : com.fasterxml.jackson.annotation.JsonKey
at java.net.URLClassLoader.findclass(URLClassLoader.java: 382)
at java.lang.classLoader.loadclass(classLoader.java:424)
at java.lang.ClassLoader.loadclass(classLoader .java: 357)
...63 common frames omitted
原因分析
可能是依赖没有导全,导致新旧版本依赖有冲突,造成的结果是找不到某个类或者方法
参考文章:
https://blog.csdn.net/Mustang_carrot/article/details/108364614
https://www.jianshu.com/p/4bd355715419
解决
如果是相互依赖的话, 就直接把Jackson的三个模块:jackson-core、jackson-annotations、jackson-databind全部导入1.13.1的版本
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>1.13.1</version>
</dependency>
更多推荐
已为社区贡献1条内容
所有评论(0)