Spring-boot 项目中使用 jackson 遇到的一个问题

jackson介绍

  java代码中实现序列化和反序列化的工具类

jackson使用Demo

  https://github.com/Naylor55/JavaDebrisCode/tree/branch_Java-Serializable/javaserializable

Ideal控制台报错信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2019-05-22 15:43:20.333 [main] ERROR org.springframework.boot.SpringApplication.reportFailure:837 - Application run failed
java.lang.AbstractMethodError: com.fasterxml.jackson.core.type.ResolvedType.getReferencedType()Lcom/fasterxml/jackson/core/type/ResolvedType;
    at com.fasterxml.jackson.core.type.ResolvedType.isReferenceType(ResolvedType.java:59)
    at com.fasterxml.jackson.datatype.jdk8.Jdk8TypeModifier.modifyType(Jdk8TypeModifier.java:20)
    at com.fasterxml.jackson.databind.type.TypeFactory._constructType(TypeFactory.java:413)
    at com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:354)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.getJavaType(AbstractJackson2HttpMessageConverter.java:323)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canRead(AbstractJackson2HttpMessageConverter.java:158)
    at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canRead(AbstractJackson2HttpMessageConverter.java:150)
    at org.springframework.web.client.RestTemplate$AcceptHeaderRequestCallback.doWithRequest(RestTemplate.java:805)
Disconnected from the target VM, address: '127.0.0.1:57769', transport: 'socket'
    at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:868)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:685)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:644)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:564)
    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:218)
    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:96)
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:94)
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:628)
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:364)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
    at com.leading.WarehouseserviceApplication.main(WarehouseserviceApplication.java:50)

  

 

报错原因

  Spring-Boot框架自身默认就引用了jackson,如果你在自己的开发项目中再次引用,就会有冲突。然而,JVM 不会告诉你是引用有冲突,而是直接给你一个类型有问题的提示。意思就是我只能告诉你类型有问题,具体的你自己查吧。IDEAL 作为一个开发工具,在这点上面也没有做出点贡献。Java这个生态缺陷还是很大的!!!

  spriing-boot 默认引用

  自己项目的pom中找到:org.springframework.boot , 并点击进去。

1
2
3
4
5
6
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.6.RELEASE</version>
    <relativePath />
</parent>

  然后再找:spriing-boot-dependencies ,并点击进去

1
2
3
4
5
6
<parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-dependencies</artifactId>
       <version>2.0.6.RELEASE</version>
       <relativePath>../../spring-boot-dependencies</relativePath>
   </parent>

  然后就可以看到spring-boot 对jackson 的引用,如下图

  

 

解决办法

  在当前开发项目的pom文件中删除对jackson的依赖,即删除如下图所示

  

 

posted @   Naylor  阅读(2884)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示