参考Spring kafka doc,我正在尝试实现一个Spring Boot应用程序,该应用程序可以手动监听kafka主题并确认。
@SpringBootApplication
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
@KafkaListener(topics = "sample_log", containerFactory = "kafkaManualAckListenerContainerFactory")
public void listen(ConsumerRecord<?, ?> cr, Acknowledgment ack) throws Exception {
process(cr);
ack.acknowledge();
}
}
但是当我运行应用程序时,它会显示:
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean named 'kafkaManualAckListenerContainerFactory' that could not be found.
Action:
Consider defining a bean named 'kafkaManualAckListenerContainerFactory' in your configuration.
就我而言,Spring Kafka可能已经定义了kafkaManualAckListenerContainerFactory
bean,因为它是一个提供的功能。如何在不手动定义bean的情况下修复错误?
答案 0 :(得分:1)
您不需要containerFactory = "kafkaManualAckListenerContainerFactory"
配置。只需将其完全删除,并依赖于Kafka的Spring Boot自动配置:https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/#boot-features-kafka