I would like to contribute an annotation to the spring-boot-autoconfigure project: @ConditionalOnPropertySource.
The point would be to add to the existing body of convenience annotations for the use case where a property source is present/missing in the environment.
Would you accept a PR for this feature? Just wanted to confirm this would be accepted before I did the work.
Comment From: wilkinsona
Can you please explain the use case for something being conditional on the presence of a particular property source? Generally speaking, individual property sources and their names are quite low-level and not something that I'd expect an auto-configuration to react to.
Comment From: vab2048
I am creating a 'platform-defaults' project which contains a whole host of property sources with 'default values' for different use cases (kafka, auth, etc). The point of the module is to contain the 'defaults' feature all in one place.
Then there are other specific modues which depend on the defaults (and will either enable or disable them) and will also have autoconfigurations which will add specific beans depending on whether the platform-default feature's property source is present.
Comment From: wilkinsona
Thanks for the additional details.
Then there are other specific modues which depend on the defaults (and will either enable or disable them) and will also have autoconfigurations which will add specific beans depending on whether the platform-default feature's property source is present.
The property sources sound like an implementation detail of each platform-default feature. From what you're said thus far, I would add the specific beans as a direct consequence of a particular set of defaults being enabled rather than through the indirect approach of looking for the property source.
All in all, I feel that what you're doing is sufficiently unusual that it doesn't warrant out-of-the-box support in Spring Boot itself. Let's see what the rest of the team thinks though.
Comment From: bclozel
I can't think of a use case for this in Spring Boot and how we could support it. I'm not in favor of implementing this in the Spring Boot codebase.
Comment From: vab2048
It would be quite simple to support right?
context.getEnvironment().getPropertySources().contains("nameOfPropertySource");
I guess I can get this to work by having a specific "enabled" property for each feature and using @ConditionalOnProperty.
Comment From: philwebb
I agree with the the others in the team, I don't think this would be a broadly use condition. I would suggest developing your own annotation and Condition implementation for this purpose.