繁体   English   中英

Spring Cloud 流多绑定器 - 错误 KStreamBinderConfiguration 需要单个 bean,但找到了 2 个

[英]Spring cloud stream multi binder - Error KStreamBinderConfiguration required a single bean, but 2 were found

我有一个用例,其中单个 kafka 流处理 MS 将有一个处理器和一个消耗处理器输出消息的消费者。 类似于 github 中的以下示例

https://github.com/spring-cloud/spring-cloud-stream-samples/tree/master/kafka-streams-samples/kafka-streams-message-channel

在执行上述示例时,我收到以下错误

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

Description:

Parameter 0 of method provisioningProvider in org.springframework.cloud.stream.binder.kafka.streams.KStreamBinderConfiguration required a single bean, but 2 were found:
    - kafkaBinderConfigurationProperties: defined by method 'kafkaBinderConfigurationProperties' in org.springframework.cloud.stream.binder.kafka.streams.MutliBinderPropertiesConfiguration
    - binderConfigurationProperties: defined by method 'binderConfigurationProperties' in class path resource [org/springframework/cloud/stream/binder/kafka/streams/KafkaStreamsBinderSupportAutoConfiguration.class]


Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

从 Spring Cloud 的角度来看,这似乎是某种搞砸了。

这个神秘的线程建议将依赖项( org.springframework.cloud:spring-cloud-stream-binder-kafka-streamsorg.springframework.cloud:spring-cloud-stream对我来说)从3.0.1.RELEASE3.0.0.RELEASE . 3.0.0.RELEASE

这确实是我版本的这个问题的修复,我想它也适合你。

当我在运行我的项目的类之外使用 @SpringBootApplication 和 @EnableBinding( Processor.class ) 以及下面的两个依赖项时,我发生了这个错误。

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-kafka</artifactId>
        </dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-stream-binder-kafka-streams</artifactId>
</dependency>

这两个依赖项都为 provisioningProvider 提供了配置,因此要解决该问题,我们必须指定要使用的配置。

在 application.yml 文件中,设置默认绑定器以解决此问题。

spring:
   cloud:
      stream:
         kafka:
            binder:
               brokers: localhost
               defaultBrokerPort: 9092
         bindings:
           output:
             binder: name-of-target-binder
             destination: sample-topic
         defaultBinder: name-of-target-binder

此处的文档,第 7.4 节类路径上的多个绑定器,提供了对这个问题的进一步了解。

我有一个类似的问题,我通过在我的 pom 中添加来修复它:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM