3

I'm getting this error when I'm trying to run my application

java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava/lang/Object;)V

Please find below pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>test</name>
<description>Demo project for Spring Boot</description>

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

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

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

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        <version>1.4.2.RELEASE</version>
    </dependency>

</dependencies>

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

I hope this issue was related to spring cloud and spring boot version compatibility issue. Can someone please help me to resolve it?

1
  • Letting maven handle dependency management is the right way. That way you never have to guess Commented Sep 24, 2018 at 11:23

2 Answers 2

2

Where possible, just use the latest versions to fix version issues.

Changing 1.4.2.RELEASE to 2.0.1.RELEASE works.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>

Ideally you should remove the version completely, let Spring Boot take care of it.

3
  • Can i know what was the exact reason to change version? Thanks! Commented Sep 24, 2018 at 6:28
  • 1
    Not all versions are compatible with all versions of another library. For example, library1 is trying to call a method helloWorld() of library2 (version 1.0). Now if you upgrade library2 to version 2.0, this version may have the helloWorld method changed to hiWorld(). So you need to upgrade library1 as well, which would be calling the updated hiWorld() method.
    – Kartik
    Commented Sep 24, 2018 at 6:35
  • Clearly explained Thanks!! Commented Sep 24, 2018 at 6:40
2

I tend to use dependency versions provided by Spring Cloud project in my dependencyManagement section: http://projects.spring.io/spring-cloud/

This way I don't have to manually put dependency versions and avoid problems like you just presented. Selecting dependency versions manually quickly becomes a huge pain and this approach uses versions that are tested by the community.

In case of Spring Cloud, Finchley release train works with Spring Boot 2.

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.0.1.RELEASE</version>
</parent>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-dependencies</artifactId>
      <version>Finchley.SR1</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
  </dependency>
</dependencies>
2
  • Instead of individual version like as i have done in my pom.xml <version>Finchley.SR1</version> this statement will take care of child dependencies right? Commented Sep 24, 2018 at 6:40
  • @thejasaitheja Exactly. Just like spring-boot-starter-parent takes care of core Spring dependencies (e.g. spring-boot-starter-web), spring-cloud-dependencies takes care of all your Spring Cloud dependencies, so you can just skip adding explicit versions in your POM.
    – Archie
    Commented Sep 24, 2018 at 6:54

Not the answer you're looking for? Browse other questions tagged or ask your own question.