Zipkin.reporter.在docker中与带有kafka的Zipkin一起使用时找不到Sender bean



我正在研究微服务,其中微服务相互通信。我使用Zipkin与Sleuth和Apache Kafka作为消息代理,并使用docker compose运行微服务和Kafka。

我使用的是Spring Boot(2.2.6.RELEASE(、Spring Cloud(Hoxton.SR3(、Kafka Image(wurstmeister/Kafka:2.12-2.4.1(和Zipkin的最新图像。

当我尝试旋转容器时,微服务给出以下错误:

应用程序无法启动

描述:

org.springframework.cloud.sleuth.zip中方法报告程序的参数2。zipkin2.Zipkin自动配置>需要一个类型为"zipkin2.reporter.Sender"的bean,但找不到该bean。

pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.adi.example</groupId>
<artifactId>currency-conversion-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>currency-conversion-service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>conversion-server</finalName>
</build>
</project>

Application.properties
spring.application.name=exchange-service
server.port=9000

eureka.client.fetch-registry=true
eureka.client.register-with-eureka=true
#eureka.client.service-url.defaultZone=http://localhost:9765/eureka/
eureka.client.service-url.defaultZone=http://eureka-server:9765/eureka/
eureka.instance.prefer-ip-address=true
spring.sleuth.sampler.probability=1
spring.zipkin.base-url=http://zipkin-server:9411/
spring.zipkin.sender.type=kafka
spring.kafka.bootstrap-servers=http://kafka:9092
docker-compose.yml
version: '3'
services: 

zookeeper: 
image: wurstmeister/zookeeper
container_name: zookeeper-server
ports:
- "2181:2181"
environment:
- ALLOW_ANONYMOUS_LOGIN= 'yes'
networks:
- service-network

kafka: 
image: wurstmeister/kafka:2.12-2.4.1
container_name: kafka-server
ports: 
- "9092:9092"
depends_on: 
- zookeeper
networks: 
- service-network
environment: 
- KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR= 1
- KAFKA_ZOOKEEPER_CONNECT= zookeeper:2181
- KAFKA_LISTENERS= PLAINTEXT://:9092
- KAFKA_ADVERTISED_LISTENERS= PLAINTEXT://:9092


eureka-server:
image: discovery-server:1.0.0
restart: always
depends_on: 
- zipkin-server
ports: 
- "9765:9765"
networks: 
- service-network

exchange-server: 
image: exchange-server:1.0.0
restart: always
ports: 
- "9000:9000"
depends_on: 
- eureka-server
networks: 
- service-network

conversion-server: 
image: conversion-server:1.0.0
restart: always
ports: 
- "9100:9100"
depends_on: 
- eureka-server
- exchange-server
networks: 
- service-network

zipkin-server: 
image: openzipkin/zipkin
ports: 
- "9411:9411"
restart: always
depends_on: 
- zookeeper
networks:
- service-network  

networks: 
service-network: 
console-log
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _    
( ( )___ | '_ | '_| | '_ / _` |    
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-04-22 15:03:47.165 INFO [exchange-service,,,] 1 --- [ main] c.e.d.CurrencyExchangeServiceApplication : No active profile set, falling back to default profiles: default
2020-04-22 15:03:51.847 INFO [exchange-service,,,] 1 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=a980a587-b2e4-3cb6-b4e7-9abfad8a56f8
2020-04-22 15:03:55.619 INFO [exchange-service,,,] 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9000 (http)
2020-04-22 15:03:55.687 INFO [exchange-service,,,] 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-04-22 15:03:55.688 INFO [exchange-service,,,] 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-04-22 15:03:55.890 INFO [exchange-service,,,] 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-04-22 15:03:55.893 INFO [exchange-service,,,] 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 8565 ms
2020-04-22 15:03:56.382 ERROR [exchange-service,,,] 1 --- [ main] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'tracingFilter' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/TraceWebServletAutoConfiguration.class]: Unsatisfied dependency expressed through method 'tracingFilter' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'httpTracing' defined in class path resource [org/springframework/cloud/sleuth/instrument/web/TraceHttpAutoConfiguration.class]: Unsatisfied dependency expressed through method 'httpTracing' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tracing' defined in class path resource [org/springframework/cloud/sleuth/autoconfig/TraceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'tracing' parameter 6; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'zipkinReporter' defined in class path resource [org/springframework/cloud/sleuth/zipkin2/ZipkinAutoConfiguration.class]: Unsatisfied dependency expressed through method 'reporter' parameter 2; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'zipkin2.reporter.Sender' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=zipkinSender)}
2020-04-22 15:03:56.443 INFO [exchange-service,,,] 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-04-22 15:03:56.472 WARN [exchange-service,,,] 1 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
2020-04-22 15:03:56.522 INFO [exchange-service,,,] 1 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-04-22 15:03:57.082 ERROR [exchange-service,,,] 1 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
Description:
Parameter 2 of method reporter in org.springframework.cloud.sleuth.zipkin2.ZipkinAutoConfiguration required a bean of type 'zipkin2.reporter.Sender' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'rabbitSender' in 'ZipkinRabbitSenderConfiguration' not loaded because @ConditionalOnProperty (spring.zipkin.sender.type=rabbit) found different value in property 'spring.zipkin.sender.type'
- Bean method 'restTemplateSender' in 'ZipkinRestTemplateSenderConfiguration' not loaded because ZipkinSender org.springframework.cloud.sleuth.zipkin2.sender.ZipkinRestTemplateSenderConfiguration kafka sender type
Action:
Consider revisiting the entries above or defining a bean of type 'zipkin2.reporter.Sender' in your configuration.
MainApp.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import brave.sampler.Sampler;
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients("com.example")
public class MainApp {
public static void main(String[] args) {
SpringApplication.run(CurrencyConversionServiceApplication.class, args);
}

@Bean
public Sampler sampler() {
return Sampler.ALWAYS_SAMPLE;
}
}

错误背后的原因是我忘记在pom.xml中添加kafka依赖项添加依赖项后,错误消失了。

在我的案例中,我添加了@EnableConfigurationProperties({KafkaProperties.class}) to @SpringBootApplication class

@SpringBootApplication
@EnableConfigurationProperties({KafkaProperties.class})
public class Application{
...
}

最新更新