I want to have Spring load an external configuration file if present and else use the once provided in src/main/resources.
Current setup:
src/main/resources/application.properties
src/main/resources/application-dev.properties
src/main/resources/application-prod.properties
/this/is/an/external/dir/application-dev.properties
Similar to https://stackoverflow.com/a/27776123/5126654 I added the following annotations:
@EnableFeignClients
@SpringBootApplication
@EnableEncryptableProperties
@PropertySources({ //
@PropertySource("classpath:application.properties"), //
@PropertySource(value = "file:${external.config}", ignoreResourceNotFound = true) //
})
public class Application extends SpringBootServletInitializer {
// ....
}
And have the following entry in my application.properties:
external.config=/this/is/an/external/dir/application-dev.properties
I also can see that the external conifguration file is picked up. The problem I have is that every entry in the classpath properties file overwrites the external ones. I.e. instead of taking entries from /this/is/an/external/dir/application-dev.properties entries from src/main/resources/application-dev.properties are taken.
How can I modify my code such that the external file overrides the entries of the classpath file?