SpringBoot中使用Kafka报错:Failed to construct kafka consumer
Posted wufabao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SpringBoot中使用Kafka报错:Failed to construct kafka consumer相关的知识,希望对你有一定的参考价值。
报错内容
在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
原因在报错中很清晰了,消费者反序列化使用的类错误
解决方案
把spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.IntegerSerializer
改为
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.IntegerDeserializer
就好了
以上是关于SpringBoot中使用Kafka报错:Failed to construct kafka consumer的主要内容,如果未能解决你的问题,请参考以下文章
springboot 微信支付里的app支付坑注意,requestPayment,支付报错,"errMsg":"requestPayment:fail:[payment微