SpringCloud踩坑


今天在使用 SpringCloud 時遇到了一個問題,感覺有不少小伙伴會遇到,所以記錄下來

版本說明

SpringBoot		2.2.4.RELEASE
SpringCloud		Greenwich.SR1

情景復現

在 pom.xml 中加入如下依賴

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

啟動項目后報錯 The following method did not exist: org.springframework.boot.actuate.health.CompositeHealthIndicator

***************************
APPLICATION FAILED TO START
***************************

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:/Volumes/Others/MVNrepository/org/springframework/boot/spring-boot-actuator/2.2.4.RELEASE/spring-boot-actuator-2.2.4.RELEASE.jar!/org/springframework/boot/actuate/health/CompositeHealthIndicator.class

It was loaded from the following location:

    file:/Volumes/Others/MVNrepository/org/springframework/boot/spring-boot-actuator/2.2.4.RELEASE/spring-boot-actuator-2.2.4.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.boot.actuate.health.CompositeHealthIndicator

問題分析

問題所在就是——版本沖突
我使用的 SpringBoot 版本是2.2.4,而 SpringCloud 版本是 Greenwich,二者的兼容還是有一定問題的,所以在啟動時會報錯:在 spring-boot-actuator-2.2.4.RELEASE.jar 下找不到 CompositeHealthIndicator.class

解決方法

解決方法有如下兩種,我都已經測試過,這兩種方法都可以解決問題

  1. 降級 SpringBoot
    把 SpringBoot 從 2.2.4.RELEASE 降級成 2.1.4.RELEASE
  2. 升級 SpringCloud
    把 SpringCloud 從 Greenwich.SR1 升級成 Hoxton.SR1

按如上所示即可成功解決問題,小伙伴們趕緊去試一下吧~


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM