简体   繁体   中英

maven dependency hell: java.lang.NoSuchMethodError

I am trying to convert one of our existing maven projects to spring boot. I dont have any compile errors in my project but when I try to run it I get the following error:

Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.MultiValueMap.addAll(Ljava/lang/Object;Ljava/util/List;)V
at org.springframework.core.io.support.SpringFactoriesLoader.loadSpringFactories(SpringFactoriesLoader.java:140)
at org.springframework.core.io.support.SpringFactoriesLoader.loadFactoryNames(SpringFactoriesLoader.java:119)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:426)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:418)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:266)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:247)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
at com.myorg.MyMainClass ...

My POM:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>compile</scope>
        </dependency>

    <dependency>
        <groupId>couple of our other internal projects</groupId>
        **One of these projects is using spring-context and spring-orm** dependencies. 
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

Since the spring dependencies in my own project are declared before the other projects I would have thought it would override any of those transitive dependencies.

I have wasted an entire day on this. Can some one please help?

Since the spring dependencies in my own project are declared before the other projects I would have thought it would override any of those transitive dependencies.

That is in fact the issue. Your project is dictating what is included, but some of the dependencies require a different version. They are still trying to call the method that exists in their version, but not in yours, and can't find it because you've forcibly excluded their version. That should not be done unless you're confident that the two versions are compatible!

Solutions:

  1. Align on a single version, and use that
  2. Use more compatible versions
  3. Include both versions via shading (see this post ) or a similar mechanism

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM