java - 创建名为“kafkaListenerContainerFactory”的 bean 时

我是 kafka、springboot 的新手,正在尝试将 kafka 和 elasticsearch 集成到我的 springboot 应用程序中。

当我尝试运行 springboot 应用程序时,我看到以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaListenerContainerFactory' defined in class path resource [org/springframework/boot/autoconfigure/kafka/KafkaAnnotationDrivenConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory]: Factory method 'kafkaListenerContainerFactory' threw exception; nested exception is java.lang.NoSuchMethodError:org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory.getContainerProperties()Lorg/springframework/kafka/listener/config/ContainerProperties;

我的 pom.xml

 <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
            <version>2.2.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>net.java.dev.jna</groupId>
            <artifactId>jna</artifactId>
            <version>4.1.0</version>
        </dependency>

应用程序.yml

  security:
    enabled: true

spring:
  resources:
    chain:
      enabled: true

kafka:
  consumer:
    bootstrap-servers: localhost:9092
    group-id: group-id
    auto-offset-reset: earliest
    key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
    value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
  producer:
    bootstrap-servers: localhost:9092
    key-serializer: org.apache.kafka.common.serialization.StringSerializer
    value-serializer: org.apache.kafka.common.serialization.StringDeserializer


生产者类


@Service
public class Producer {
    private static final Logger logger = LoggerFactory.getLogger(Producer.class);
    private static  final  String topic = "users";

    @Autowired
    private KafkaTemplate<String, String> kafkaTemplate;

    public void sendMessage(History t){
        logger.info("Inside send message to topic");
        this.kafkaTemplate.send(topic,"HelloWorld");
    }

}

消费者.java

package com.springboot.kafka;

import com.springboot.model.History;
import com.springboot.repository.HistoryRepository;
import org.apache.kafka.common.protocol.types.Field;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

@Service
public class Consumer  {
    private static final Logger logger = LoggerFactory.getLogger(Consumer.class);
    private static  final  String topic = "users";


    @KafkaListener(topics = topic,groupId = "group-id")
    public void consume (String t){
        logger.info("Message read as " + t);

    }
}

应用程序属性:

logging.level.sql=info
logging.file = /var/tmp/SpringBootAppLog.log
spring.datasource.driver=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/test
spring.datasource.username=postgres
spring.datasource.password=postgres

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.hibernate.ddl-auto=update
spring.data.elasticsearch.cluster-name=my-application
spring.data.elasticsearch.cluster-nodes=localhost:9200

关于我遗漏了什么的任何想法。任何线索将不胜感激。

最佳答案

您应该检查完整的错误日志(堆栈跟踪)。在我的例子中,问题是由下面的 java.io.FileNotFoundException 引起的。
您通常会在堆栈跟踪的末尾发现您的“真正”问题。

关于java - 创建名为“kafkaListenerContainerFactory”的 bean 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58234179/

相关文章:

angular - Ionic Barcode Scanner 插件关闭按钮

aws-lambda - 如何使用 CloudFormation 添加订阅过滤器?

java - elasticsearch 中的 too_many_buckets_exception

google-maps - google_maps_flutter 或任何其他用于 flutter

flutter - Google AdMob 奖励视频有时只加载

react-native - null 不是对象(评估 'StripeModule.init' )

r - 在 R 中使用 RCurl 下载 NASA 卫星数据

swift - animateTransition 不再适用于 iOS 13 中以模态呈现的 vie

r - R : how to find the place of maximum memory us

reactjs - Jest 测试无法使用 create react app 和 craco 导入铯