Skip to content

Add spring.kafka.enabled configuration to disable KafkaAutoConfiguration #41687

Open
@DanielLiu1123

Description

@DanielLiu1123

Background

In our use case, we need to support connecting to multiple Kafka servers. Spring does not support this. We want to use Spring's KafkaTemplate, but when spring-kafka and spring boot are both on the classpath, KafkaAutoConfiguration is automatically activated, and there is no configuration like spring.kafka.enabled to disable the auto-configuration.

Why not use @SpringBootApplication(exclude = KafkaAutoConfiguration.class) to exclude the auto-configuration class?

Changing code for every service just sucks... We will provide a library to support configuring multiple Kafka servers, like creating our own Spring Boot starter.

More thoughts

Consider providing a spring.<module>.enabled configuration for Spring Boot modules (e.g., spring.datasource.enabled, spring.redis.enabled). When users develop based on Spring Boot, if there is this configuration, they do not need to force auto-configuration because sometimes users just want to use Spring's code (JdbcTemplate, RedisTemplate), not auto-configuration. I have written some Spring Boot starters, and I always provide an enabled configuration for a feature (with a reasonable default value). It works very well and makes testing easier.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions