java中springboot集成kafka生产者Producer启动报错kafkaTemplate模板报错

前言:之前博客里面提到本公司为物联网项目。项目中使用mqtt+kafka进行与设备端的通讯,之前的协议格式为json格式,现在改成字节数组byte[]格式进行通信。

  • 报错信息如下
Can't convert value of class [B to class org.apache.kafka.common.serialization.StringSerializer specified in value.serializer

Field kafkaTemplateByte in com.hiss.producer.KafkaNewProducer required a bean of type 'org.springframework.kafka.core.KafkaTemplate' that could not be found.
- Bean method 'kafkaTemplate' in 'KafkaAutoConfiguration' not loaded because @ConditionalOnMissingBean (types: org.springframework.kafka.core.KafkaTemplate; SearchStrategy: all) found bean 'kafkaTemplate'


Action:
Consider revisiting the conditions above or defining a bean of type 'org.springframework.kafka.core.KafkaTemplate' in your configuration.

  • 分析原因
    之前声明KafkaTemplate时候value值为String,后续改为byte[]时候,未将KafkaTemplate的value类型改为byte[]类型。

  • 解决办法

 public KafkaTemplate kafkaTemplateByte() {
    	return new KafkaTemplate(producerFactoryByte());
    }

你可能感兴趣的:(kafka,报错解决)