Spring @PropertySources value not overriding
Instead of using many propertySource annotation try setting while starting application
java -jar myproject.jar --spring.config.location={your_location}/application.properties,classpath:/override.properties.
Whatever you provide as part of commandline will be of the highest
precedence.
Or Do something like this and test
@Configuration
@PropertySource("classpath:application.properties")
public class DefaultConfiguration {}
@Configuration
@PropertySource("classpath:{environment_specific_property_name}.properties")
public class EnvironmentSpecific{
@Configuration
@Import(DefaultConfiguration .class)
static class Configuration {}
}
Instead of application.properties, place your default configuration / properties in a different file. It seems property values defined in application.properties has the highest precedence.
So, something like this will work:
@Configuration
@PropertySource("classpath:application-env.properties")
@PropertySource(value="file:${application.home}/application-env.properties",ignoreResourceNotFound=true)
public class GlobalSettings {
//configuration values
}
Tested in Spring 4.x and Java 8