I have an external properties file that is present in Hashicorp and am pulling it to Spring Boot using @PropertySource
annotation.
In my Spring Boot application, there are profile specific application.properties
files.
Now what I want is the PropertySource
config to take precedence over these profile specific config.
I read through the Spring Boot External Config doc already- https://docs.spring.io/spring-boot/docs/2.1.13.RELEASE/reference/html/boot-features-external-config.html which mentions PropertySource
config is least preference
@PropertySource(value="${path}",ignoreResourceNotFound = true)
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
In my application.properties file-
name=value
In my external config file-
name=updatedNewValue
What I want is to retrieve the the 'updatedNewValue', instead I get 'value'.
Is it possible to override it?
CodePudding user response:
Specific profiles take precedence over the default profile. You can have placename=value in your file.properties (or properties.yml) and a second file named file-.properties (test, prod, stage are common options) with the placeholder placename=value.
Remember to provide the profile the application as configuration before running it.
CodePudding user response:
If you want to overwrite a property for a specific profile, using an external configuration, your external file/source must be profile specific:
properties-profile.properties
(if it's file-based)
You mentioned Hashicorp... Not sure if it's Vault or Consul, but for Vault, you can define a profile-specific value using:
vault write secret/application,profile foo=bar