报错内容
在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
就好了
本文转载自: https://blog.csdn.net/qq_41413743/article/details/123147634
版权归原作者 wufabao 所有, 如有侵权,请联系我们删除。
版权归原作者 wufabao 所有, 如有侵权,请联系我们删除。