Search code examples
javaspringspring-bootspring-kafkaspring-boot-test

How to disable `@EnableKafka` in Spring Boot tests?


I would like to run my integration tests but I don't know how to disable @EnableKafka.

My app looks like that:

@SpringBootApplication
@EnableKafka
public class MyApplication {

Solution

  • Spring Boot come with an auto-configuration for Spring Kafka, therefore you don't need to use an explicit @EnableKafka. What you need to do in your test is just exclude KafkaAutoConfiguration:

    @SpringBootTest("spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration")