今天springboot 项目配置kafka消费者,出现了一个错误
com.fasterxml.jackson.databind.deser.std.StringDeserializer is not an instance of org.apache.kafka.common.serialization.Deserializer
at org.apache.kafka.common.config.AbstractConfig.getConfiguredInstance(AbstractConfig.java:263)
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:688)
从报错信息可以看出,com.fasterxml.jackson.databind.deser.std.StringDeserializer 不是
org.apache.kafka.common.serialization.Deserializer的实例,说明引用jar包引用错误
查找代码,发现
propsMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
propsMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
StringDeserializer引用的jar引用错了
错误引用:
import com.fasterxml.jackson.databind.deser.std.StringDeserializer;
正确的引用:
import org.apache.kafka.common.serialization.StringDeserializer;
java交流群,欢迎大佬和java学习者加入:3446-35699