首页 > 解决方案 > Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup

问题描述

我目前正在玩Spring BootGCP 数据存储中的一些概念验证工作。

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

问题:Spring Boot 无法启动

当我尝试启动应用程序时,我得到:

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)

我试过的

我尝试添加Actuator依赖项。但这并没有奏效。我无法弄清楚我缺少什么依赖项。我在 5.3.0-M2 文档中看到了类定义,但我不确定它存在于什么依赖项中。

我还尝试添加以下指标依赖项:

我在findjar.com中搜索,但没有成功。

如果可能的话,我也不介意禁用它。


更新:

我补充说:

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

这给了我一个新的错误:

试图调用不存在的方法。尝试是从以下位置进行的:

org.springframework.boot.SpringApplication.run(SpringApplication.java:324)

以下方法不存在:

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

该方法的类 org.springframework.context.ConfigurableApplicationContext 可从以下位置获得:

... 行动:

更正应用程序的类路径,使其包含一个兼容的 org.springframework.context.ConfigurableApplicationContext 版本

标签: spring-bootdependenciespom.xmlnoclassdeffounderror

解决方案


我可以通过降级 Spring Boot 来解决这个问题:

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

猜猜它只是与 2.4.0 不兼容。

具体来说,我还必须确保我使用的是 2.3.3.RELEASE 而不是由于我遇到的其他问题而更新的任何东西。


推荐阅读