使用多模块Maven项目时,Eclipse的类路径问题

时间:2019-07-18 09:28:46

标签: java eclipse maven

我有一个带有多个子模块的spring-boot 2项目。

某些模块使用包含jackson-databind的库。我为他们添加了排除对象。在进行mvn dependency:tree | grep jackson-databind时,我没有2.2.2依赖性。使用mvn spring-boot:run可以完美工作。但是,在Eclipse中启动应用程序会导致以下错误。

我应该在哪里搜索错误源?

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

The following method did not exist:

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

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

    jar:file:/C:/Users/somebody/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.2.2/jackson-databind-2.2.2.jar!/com/fasterxml/jackson/databind/Module.class
    jar:file:/C:/Users/somebody/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.6.6/jackson-databind-2.6.6.jar!/com/fasterxml/jackson/databind/Module.class
    jar:file:/C:/Users/somebody/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.9.8/jackson-databind-2.9.8.jar!/com/fasterxml/jackson/databind/Module.class
    jar:file:/C:/Users/somebody/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.8.8/jackson-databind-2.8.8.jar!/com/fasterxml/jackson/databind/Module.class

It was loaded from the following location:

    file:/C:/Users/somebody/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.2.2/jackson-databind-2.2.2.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.fasterxml.jackson.databind.Module

1 个答案:

答案 0 :(得分:0)

嗯似乎项目被错误地导入了eclipse中。也许是mvn eclipse:eclipse的罪魁祸首。

  • 从工作区中删除项目
  • 删除所有的Eclipse项目文件(.project.classpath等)
  • 将它们放入.gitignore
  • 通过import maven project
  • 导入项目

现在可以了。