问题
先介绍下最初这个项目所依赖的 SpringCloud、SpringBoot 版本,如下:
- SpringCloud : Greenwich.SR1
- spring-boot-starter-parent : 2.1.3.RELEASE
近期由于项目需要,将该项目中的 spring-boot-starter-parent 升级到了 2.3.5.RELEASE,此时启动项目的时候会抛出如下错误:
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.cloud.client.discovery.health.DiscoveryCompositeHealthIndicator.<init>(DiscoveryCompositeHealthIndicator.java:42)
The following method did not exist:
org.springframework.boot.actuate.health.CompositeHealthIndicator.<init>(Lorg/springframework/boot/actuate/health/HealthAggregator;)V
The method's class, org.springframework.boot.actuate.health.CompositeHealthIndicator, is available from the following locations:
jar:file:/Users/eric/.m2/repository/org/springframework/boot/spring-boot-actuator/2.3.5.RELEASE/spring-boot-actuator-2.3.5.RELEASE.jar!/org/springframework/boot/actuate/health/CompositeHealthIndicator.class
The class hierarchy was loaded from the following locations:
org.springframework.boot.actuate.health.CompositeHealthIndicator: file:/Users/eric/.m2/repository/org/springframework/boot/spring-boot-actuator/2.3.5.RELEASE/spring-boot-actuator-2.3.5.RELEASE.jar
解析
从上边的报错信息来看,大概的意思是 SpringCloud 在进行健康检查的时候,无法在 spring-boot-actuator-2.3.5.RELEASE.jar 中找到 CompositeHealthIndicator。这个问题应该是 SpringCloud 的版本(Greenwich.SR1)与 SpringBoot 的版本(2.3.5.RELEASE)不匹配而导致的。
解决
既然是版本不匹配导致的,那问题就简单了,只要调整下 SpringCloud 或 SpringBoot 的版本调整到可匹配就好了。若不能降低 SpringBoot 的版本(由于其他 jar 包依赖该版本的 SpringBoot),那我们可以单独将 spring-boot-actuator 的版本降级,以此来匹配较低版本的 SpringCloud,如下图: