解决 Spring Cloud 整合 zipkin 报错:org.springframework.boot.actuate.health.CompositeHealthIndicator......

一、问题描述

     我的 Spring Boot 版本是 2.3.4,Spring Cloud 版本是 Hoxton.SR1。
要整合 zipkin,先在服务端导入了以下依赖:

	<dependencies>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-server</artifactId>
            <version>2.9.4</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.logging.log4j</groupId>
                    <artifactId>log4j-slf4j-impl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.zipkin.java</groupId>
            <artifactId>zipkin-autoconfigure-ui</artifactId>
            <version>2.9.4</version>
        </dependency>
    </dependencies>

    
提供配置文件:

server:
  port: 9090
spring:
  main:
    allow-bean-definition-overriding: true

    
然后提供启动类:

@SpringBootApplication
@EnableZipkinServer
public class ZipKinApplication {
    
    
    public static void main(String[] args) {
    
    
        SpringApplication.run(ZipKinApplication.class,args);
    }
}

接下来,运行 zipkinserver 启动类,结果报错了:
在这里插入图片描述


把整个报错信息复制下来是这样的:
Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:
zipkin.server.internal.ZipkinHealthIndicator.(ZipkinHealthIndicator.java:26)

The following method did not exist:
org.springframework.boot.actuate.health.CompositeHealthIndicator.(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:/D:/Maven/maven_repository/org/springframework/boot/spring-boot-actuator/2.3.4.RELEASE/spring-boot-actuator-2.3.4.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:/D:/Maven/maven_repository/org/springframework/boot/spring-boot-actuator/2.3.4.RELEASE/spring-boot-actuator-2.3.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


     大意是说 试图调用不存在的方法 zipkin.server.internal.ZipkinHealthIndicator 方法,但是在启动类中 @EnableConfigServer 注解是没有爆红的,import zipkin.server.internal.EnableZipkinServer; 是导入没问题的:

在这里插入图片描述

     我照着 它说重复了的 jar 包的路径 The class hierarchy was loaded from the following locations: 把 jar 包删掉,结果连 eureka 注册中心都报错了… …
     问题在于, SpringBoot2.2.x 以后的版本 集成 zipkin 的方式改变了,原来是通过@EnablezipkinServer注解,现在这个注解不起作用了。
    

二、解决方法

     服务端应该通过下载 jar 包,然后 运行 jar 包来集成 。 在 https://dl.bintray.com/openzipkin/maven/io/zipkin/java/zipkin-server/ 可以选择版本来下载,要选择 后缀为 -exec.jar 的(我的 Spring Boot 是 2.3.4 ,选择的 zipkin 是 2.12.8,是可以用的 ),之后切换到 jar 包在的路径,然后用 java -jar 的方式启动就可以了(默认端口号是 9411 ,所以如果提供了 zipkin client,需要把它的配置文件中的端口号改成 9411,对应的配置应该是 zipkin: base-url: http://localhost:9411):
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41750142/article/details/113808361