spring-integration-kafka2.1配置异常找不到listener-container

发布于 2021-12-01 14:20:01 字数 4436 浏览 448 评论 1

在配置消费者的时候出现的异常如下,找不到container1这个参数配置,在spring-integration-kafka.xsd找了发现listener-container指向的是org.springframework.integration.kafka.listener.KafkaMessageListenerContainer,但是在spring-integration-kafka里面没有发现这个类,不知道大家有没有碰到过这个问题,又是如何解决的

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaListener': Cannot resolve reference to bean 'container1' while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'container1' defined in file [C:sts-bundlests-3.7.3.RELEASEworkspace.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebappsiamyun_apiWEB-INFclassesspring-integration-kafka-consumer.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.kafka.listener.config.ContainerProperties]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'container1' defined in file [C:sts-bundlests-3.7.3.RELEASEworkspace.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebappsiamyun_apiWEB-INFclassesspring-integration-kafka-consumer.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.kafka.listener.config.ContainerProperties]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?

 

 

配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:int-kafka="http://www.springframework.org/schema/integration/kafka"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="
          http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/integration/kafka
         http://www.springframework.org/schema/integration/kafka/spring-integration-kafka-2.1.xsd
         http://www.springframework.org/schema/integration
         http://www.springframework.org/schema/integration/spring-integration-4.3.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-4.2.xsd">  
 

<bean id="container1" class="org.springframework.integration.kafka.listener.KafkaMessageListenerContainer">
    <constructor-arg>
<bean class="org.springframework.kafka.core.DefaultKafkaConsumerFactory">
    <constructor-arg>
    <map>
        <entry key="bootstrap.servers" value="localhost:9092" />
        <entry key="key.deserializer" value="org.apache.kafka.common.serialization.StringDeserializer"></entry>
                        <entry key="value.deserializer" value="org.apache.kafka.common.serialization.StringDeserializer"></entry>
                    </map>
    </constructor-arg>
    </bean>
    </constructor-arg>
    <constructor-arg name="topics" value="test" />
    </bean>         
     <int-kafka:message-driven-channel-adapter
        id="kafkaListener"
        listener-container="container1"
        auto-startup="false"
        phase="100"
        send-timeout="5000"
        channel="nullChannel"
        error-channel="errorChannel" />
</beans> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2021-12-01 23:47:14

spring对这块的管理太混乱,一个kafka的组件有2个版本,文档也不全,我放弃了直接用kafka-client现在一切都清净了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文