In my application I have these properties files:
application.properties
application-prod.properties
Inside I have the same property
spring.datasource.password=my-dev-password #for the default one
spring.datasource.password=${PROD_DATABASE_PASSWORD} #for the prod file
On the server I run my application like :
java -jar "myjar.jar" --spring.profiles.active=prod
Everything works fine so far.
Now I want to use an extra file to override the same property on the server like :
java -jar myjar.jar --spring.profiles.active=prod --spring.config.additional-location=file:/to/folder/application.properties
but it didn't work !
I've tried to pass it as a java property but it didn't work neither !
java -Dspring.config.additional-location=file:/to/folder/application.properties -jar myjar.jar --spring.profiles.active=prod
What I have missed here ?
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
I'm using spring-boot 2.3.5
UPDATE
When I reference only the folder it works :
--spring.config.additional-location=file:/to/folder/
I thought that it takes only folder in contrary to spring.config.location
but when I've looked to the code both are loaded with the same code in ConfigFileApplicationListener :
private Set<String> getSearchLocations() {
Set<String> locations = getSearchLocations(CONFIG_ADDITIONAL_LOCATION_PROPERTY);
if (this.environment.containsProperty(CONFIG_LOCATION_PROPERTY)) {
locations.addAll(getSearchLocations(CONFIG_LOCATION_PROPERTY));
}
else {
locations.addAll(
asResolvedSet(ConfigFileApplicationListener.this.searchLocations, DEFAULT_SEARCH_LOCATIONS));
}
return locations;
}