spring集成kafka运行时报错:Failed to construct kafka producer] with root cause
org.apache.kafka.common.KafkaException: class org.apache.kafka.common.serialization.StringDeserializer is not an instance of org.apache.kafka.common.serialization.Serializer
如图:
解决方案,spring框架里面的kafka的消费者和生产者的key和value解析器用spring支持的,在application.properties配置spring支持的解析器:
spring.kafka.consumer.key-deserializer=org.springframework.kafka.support.serializer.StringOrBytesSerializer
spring.kafka.consumer.value-deserializer=org.springframework.kafka.support.serializer.JsonSerializer
spring.kafka.producer.key-serializer=org.springframework.kafka.support.serializer.StringOrBytesSerializer
spring.kafka.producer.value-serializer=org.springframework.kafka.support.serializer.JsonSerializer