Warm tip: This article is reproduced from serverfault.com, please click

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

发布于 2020-11-28 03:15:00

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

In my pom.xml I have:

<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>

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)

I tried adding Actuator and that did not do the trick, but 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 in:

  • 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

Questioner
el n00b
Viewed
0
el n00b 2020-11-28 12:41:18

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.