-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add spring.kafka.enabled configuration to disable KafkaAutoConfiguration #41687
Comments
Btw, you can also exclude auto-configurations via properties. That way you can set it via the environment and don't have to change code. Does that solve your problem? |
See #38641. |
I'd prefer #41669, is it suitable for your use case? @DanielLiu1123 |
I did miss that configuration, but I think manually excluding auto-configuration is not suitable. To support connecting to multiple Kafka servers, I need to disable Kafka auto-configuration in the library. However, some services use
In our team, we avoid using environment variables or system properties to override configurations. We only inject sensitive data using environment variables. We want all configurations to be explicitly declared. |
I still don’t think manually excluding auto-configuration is a good way. For users, providing an |
|
I'm flagging this so that we can discuss it in our next team meeting. The |
spring.kafka.enabled
configuration to disable KafkaAutoConfiguration
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 anenabled
configuration for a feature (with a reasonable default value). It works very well and makes testing easier.The text was updated successfully, but these errors were encountered: