在配置中添加json序列化器
spring:application:name: spring-boot-kafka-basekafka:bootstrap-servers: 192.168.225.128:9092# 配置生产者序列化producer:value-serializer: org.springframework.kafka.support.serializer.JsonSerializer# 配置默认的topictemplate:default-topic: test
发送对象消息
public void sendEvent5(){kafkaTemplate.sendDefault(null,System.currentTimeMillis(),"k3",User.builder().age(10).name("小王").build());
}