I work on a SpringBoot application which has to run on different environments. The property files are created and once I modify the environment the default values are overridden with the proper ones. That's okay.
In the next step I want to check whether the logged in user System.getProperty("user.name")
has a custom property file. If so, these properties must be overriden with his ones. So the steps should be (let's say the active profile is dev):
- Load application.properties
- Load and override properties from application-dev.properties
- In case the user has a custom property file (user.properties), load this and override the properties
I read many topcis and found two possible solutions, but none of them worked.
- Add the annotation
@PropertySource("user.properties")
to a configuration class, which should load the user specific property file and override the values. For testing purposes, I addedserver.port=1234
to user.properties, but this was ignored. - Create a custom PropertyPlaceholderConfigurer. Although this bean was created successfully, the server port wasn't changed.
`
@Bean
public PropertyPlaceholderConfigurer propertyPlaceholder() {
PropertyPlaceholderConfigurer propertyPlaceholder = new PropertyPlaceholderConfigurer();
propertyPlaceholder.setLocations(
new ClassPathResource("application.properties"),
new ClassPathResource("application-dev.properties"),
new ClassPathResource("user.properties"));
propertyPlaceholder.setIgnoreResourceNotFound(true);
propertyPlaceholder.setIgnoreUnresolvablePlaceholders(true);
return propertyPlaceholder;
}
I don't know how to go forward. So any idea is really welcomed.
Update: I've justed pushed the demo code to GitHub. Maybe is helps to find the solution: https://github.com/aszidien/springboot.