报错内容
在SpringBoot项目中使用了Kafka,在启动的过程中报错
2022-02-26 11:44:10.422 ERROR 26148 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'; nested exception is org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:185) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE]
Caused by: org.apache.kafka.common.KafkaException: org.apache.kafka.common.serialization.IntegerSerializer is not an instance of org.apache.kafka.common.serialization.Deserializer
at org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:372) ~[kafka-clients-2.3.1.jar:na] at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:713) ~[kafka-clients-2.3.1.jar:na]
... 27 common frames omitted
原因在报错中很清晰了,消费者反序列化使用的类错误
文章来源:https://www.toymoban.com/news/detail-515239.html
解决方案
把spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.IntegerSerializer
改为spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.IntegerDeserializer
就好了文章来源地址https://www.toymoban.com/news/detail-515239.html
到了这里,关于SpringBoot中使用Kafka报错:Failed to construct kafka consumer的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!