启动springboot时报错 APPLICATION FAILED TO START 包冲突

启动springboot时报错 APPLICATION FAILED TO START 包冲突

problem

具体日志如下

***************************
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:

    org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:823)

The following method did not exist:

    com.fasterxml.jackson.databind.Module.getTypeId()Ljava/lang/Object;

The calling method's class, org.springframework.http.converter.json.Jackson2ObjectMapperBuilder, was loaded from the following location:

    jar:file:/Users/dream/.m2/repository/org/springframework/spring-web/5.3.13/spring-web-5.3.13.jar!/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.class

The called method's class, com.fasterxml.jackson.databind.Module, is available from the following locations:

    jar:file:/Users/dream/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.3.3/jackson-databind-2.3.3.jar!/com/fasterxml/jackson/databind/Module.class

The called method's class hierarchy was loaded from the following locations:

    com.fasterxml.jackson.databind.Module: file:/Users/dream/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.3.3/jackson-databind-2.3.3.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.http.converter.json.Jackson2ObjectMapperBuilder and com.fasterxml.jackson.databind.Module


Process finished with exit code 1

reason

报错日志的意思

  • com.fasterxml.jackson.databind.Module.getTypeId 这个方法不存在
  • 此方法对应的一个类 json.Jackson2ObjectMapperBuilder 来自 spring-web-5.3.13.jar 包
  • 此方法对应的另一个类 jackson.databind.Module 来自 jackson-databind-2.3.3.jar

观察maven依赖

  • 正常项目的依赖是 spring-web-5.3.13.jar 和 jackson-databind-2.13.0.jar
  • 异常项目的依赖是 spring-web-5.3.13.jar 和 jackson-databind-2.3.3.jar
  • 可以看到是 第二个包的版本低了,导致出现了包冲突

对比pom文件

  • 对比正常和异常项目,发现正常项目 springboot 依赖是来自parent节点
  • 异常项目 springboot 依赖是pom中 自定义

Snipaste_2023-12-29_15-23-11

solution

采用parent方式引入springboot可以解决问题

Snipaste_2023-12-29_15-34-46

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值