New to Spring Boot here, long-time Spring Framework user though.
I'm looking for a way to split my externalised configuration into multiple .properties
files, for better readability and manageability.
I already saw this SO answer: having the ability to specify a list of configuration file names in spring.config.name
(which, by the way, doesn't seem to be mentioned in Boot reference documentation, correct me if I'm wrong) would solve my problem perfectly, however that configuration property can be specified only via system properties or environment variables. If I try to specify it inside my application.properties
file, it gets ignored. The same happens for spring.config.additional-location
. I understand this happens because, when application.properties
is read, it's too late to tell Spring Boot to search for different externalised configuration file names. However this is not a proper solution, because the way I split my configuration should be an "implementation detail" that the consumer of my application shouldn't be aware of, so I don't expect the consumer to specify an external parameter otherwise my application breaks out-of-the-box.
I think that a way to do this should be provided. Perhaps some import mechanism for .properties
files or the ability to specify spring.config.name
even in application.properties
(some known and reasonable limitations would be acceptable).
The best I could find out is to use @PropertySource
, but this is not profile aware: unless you use some ugly nested class hack, or you put spring.profiles.active
variable in the resource name (which will break if multiple profiles have been activated), you won't get the benefit you have for application.properties
profile-specific files.
I was not able to find an "official way" to do this, apart from some statements from Spring Boot devs that say that they're rather promoting the use of a single (possibly giant...) externalised configuration file. It seems like this position is not so popular, judging from the post reactions on GitHub, and IMHO it really seems to be a basic feature missing. I have been working with multiple properties files in Spring Framework (using XML configuration) for years and I never felt that having an only huge file would have been better.
If I understand it right, in Boot 1.x this was in some way possible using the location
attribute of @ConfigurationProperties
, which is however missing in Boot 2.x.
Any suggestion?