启动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中 自定义

启动springboot时报错 APPLICATION FAILED TO START 包冲突_第1张图片

solution

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

启动springboot时报错 APPLICATION FAILED TO START 包冲突_第2张图片

你可能感兴趣的:(pits,spring,boot,后端,java)