Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup

I am currently playing with some proof-of-concept work in Spring Boot and GCP data storage.

My pom.xml

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <version>2.4.0</version>
</dependency>

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-gcp-data-datastore</artifactId>
  <version>1.2.6.RELEASE</version>
</dependency>

Issue: Spring Boot fails to start

When I attempt to launch the application, I get:

Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup
    at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:251)
    at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:264)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298)

What I tried

I tried adding the Actuator dependency. But that did not do the trick. I cannot figure out what dependency I am missing. I see the class definition here in 5.3.0-M2 documentation, but I'm not sure what dependency it exists in.

I also tried adding following metrics dependencies:

  • spring-cloud-gcp-starter-metrics
  • spring-metrics
  • spring-cloud-stream-metrics

I searched in findjar.com with no luck.

I wouldn't mind disabling it as well if that is possible.


Update:

I added:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
  <version>5.3.1</version>
</dependency>

Which gives me a new error:

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:324)

The following method did not exist:

'void org.springframework.context.ConfigurableApplicationContext.setApplicationStartup(org.springframework.core.metrics.ApplicationStartup)'

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

... Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.context.ConfigurableApplicationContext

like image 975
el n00b Avatar asked Nov 28 '20 03:11

el n00b


1 Answers

I was able to solve this by downgrading Spring Boot:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <version>2.3.3.RELEASE</version>
</dependency>

Guess it's just not compatible with 2.4.0 yet.

Specifically I also had to ensure that I used 2.3.3.RELEASE and not anything more recent due to other issues I ran across.

like image 56
el n00b Avatar answered Sep 20 '22 16:09

el n00b