Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 在docker中与带有kafka的Zipkin一起使用时未找到zipkin2.reporter.Sender bean_Spring Boot_Apache Kafka_Docker Compose_Microservices_Zipkin - Fatal编程技术网

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

Spring boot 在docker中与带有kafka的Zipkin一起使用时未找到zipkin2.reporter.Sender bean,spring-boot,apache-kafka,docker-compose,microservices,zipkin,Spring Boot,Apache Kafka,Docker Compose,Microservices,Zipkin,我正在从事微服务的工作,微服务之间相互通信。我将Zipkin与Sleuth和ApacheKafka一起用作消息代理,并使用DockerCompose运行micro服务和Kafka 我正在使用SpringBoot(2.2.6.RELEASE)、SpringCloud(Hoxton.SR3)、Kafka映像(wurstmeister/Kafka:2.12-2.4.1)和Zipkin的最新映像 当我尝试旋转容器时,micro service出现以下错误: 应用程序无法启动 说明: org.spring

我正在从事微服务的工作,微服务之间相互通信。我将Zipkin与Sleuth和ApacheKafka一起用作消息代理,并使用DockerCompose运行micro服务和Kafka

我正在使用SpringBoot(2.2.6.RELEASE)、SpringCloud(Hoxton.SR3)、Kafka映像(wurstmeister/Kafka:2.12-2.4.1)和Zipkin的最新映像

当我尝试旋转容器时,micro service出现以下错误:

应用程序无法启动

说明:

org.springframework.cloud.sleuth.zipkin2.ZipkinAutoConfiguration>中方法reporter的参数2需要找不到“zipkin2.reporter.Sender”类型的bean


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

在我的例子中,我将@EnableConfigurationProperties({KafkaProperties.class})添加到@SpringBootApplication类中

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

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;
    }

}

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