添加依赖
testImplementation "org.springframework.kafka:spring-kafka-test"
配置 KafkaTemplate
@Configuration
public class KafkaConfig {
@Autowired
EmbeddedKafkaBroker broker;
@Bean
public KafkaTemplate<String, String> template() {
return new KafkaTemplate<>(new DefaultKafkaProducerFactory<>(KafkaTestUtils.producerProps(broker)));
}
}
添加测试
<