java - In Spring Kafka, do I need to add the @EnableKafka annotation to my application?

ID : 274560

viewed : 38

Tags : javaspring-bootapache-kafkaspring-kafkajava





Top 3 Answer for java - In Spring Kafka, do I need to add the @EnableKafka annotation to my application?

vote vote

91

That is because Spring boot provides an auto configuration for Kafka via KafkaAutoConfiguration class (javadoc). When you use @EnableAutoConfiguration or @SpringBootApplication, Spring boot automatically configures Kafka for you.

You can test that by excluding the auto configuration by providing @SpringBootApplication(exclude={KafkaAutoConfiguration.class}), and Spring boot would not automatically configure Kafka for you.

If you don't use Spring boot, then you would have to use @EnableKafka to configure Kafka for your Spring app.

vote vote

82

Spring Boot auto-configures @EnableKafka if it detects spring-kafka on the class path.

It is therefore not needed again on a boot app; it is only needed if your Spring app is not a Boot app.

vote vote

71

Top 3 video Explaining java - In Spring Kafka, do I need to add the @EnableKafka annotation to my application?







Related QUESTION?