'Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.SpringApplication

I recently upgraded by sprint boot to 2.6.6 following a RCE vulnerability. However, now I application isn't starting with error:


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.boot.SpringApplication.run(SpringApplication.java:301)

The following method did not exist: 'void org.springframework.context.ConfigurableApplicationContext.setApplicationStartup(org.springframework.core.metrics.ApplicationStartup)'

The calling method's class, org.springframework.boot.SpringApplication, was loaded from the following location:

jar:file:/Users/mahulivishal/.m2/repository/org/springframework/boot/spring-boot/2.6.6/spring-boot-2.6.6.jar!/org/springframework/boot/SpringApplication.class

The called method's class, org.springframework.context.ConfigurableApplicationContext, is available from the following locations:

jar:file:/Users/mahulivishal/.m2/repository/org/springframework/spring-context/5.2.5.RELEASE/spring-context-5.2.5.RELEASE.jar!/org/springframework/context/ConfigurableApplicationContext.class

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

org.springframework.context.ConfigurableApplicationContext: file:/Users/mahulivishal/.m2/repository/org/springframework/spring-context/5.2.5.RELEASE/spring-context-5.2.5.RELEASE.jar

Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.SpringApplication and org.springframework.context.ConfigurableApplicationContext

Process finished with exit code 1

Here are dependencies from my pom.xml -

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.6</version>
    </parent>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.6.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.2.5.RELEASE</version>
    </dependency>


Solution 1:[1]

I found the solution to this. There were 2 problems in total here:

  1. spring-boot 2.6.6 wasn't compatible with spring-context 5.2.5.RELEASE
  2. Spring has moved support for netflix-zuul to maintenance mode, so Zuul wouldn't work with 2.6.6

Solution: Downgrade spring-boot to 2.4.12 (2.4.x) for Zuul support, and upgrade the spring version to 5.3.18 so to prevent exposure to the RCE vulnerability. Also, use a spring-cloud-starter-bootstrap 3.0.1 for sping-context incompatibility. remove the spring-context dependency.

    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.4.12</version>
    <properties>
       <java.version>11</java.version>
       <log4j2.version>2.16.0</log4j2.version>
       <spring.version>5.3.18</spring.version>
    </properties>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.4.12</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bootstrap</artifactId>
        <version>3.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
        <version>2.2.2.RELEASE</version>
    </dependency>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vishal Mahuli