解决Spring Boot 2.4.11报错:NoClassDefFoundError: org/springframework/core/metrics/ApplicationStartup

时间:2022-02-02 18:44:04

项目升级到Spring Boot 2.4.11,运行Application报错:

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 com.amway.commerce.commodity.Application.main(Application.java:27)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.metrics.ApplicationStartup
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more

Spring Boot从2.4开始使用了Spring Framework 5.3,可以从Spring boot 2.3升级到2.4找到此说明。其中org/springframework/core/metrics/ApplicationStartup也是Spring Framework5.3新增的类。

解决方法

如果确定要升级,那Spring Framwork 也要升级到对应的版本,2.4.11对应的版本是Spring Framework 5.3.3。否在降级Spring boot版本。

Spring Boot提供了minor版本的升级说明,其中:

参考:https://github.com/spring-projects/spring-boot/issues/24880