How to store and read multiple spring boot application profiles from vault?

42 views Asked by At

I have a Spring boot Application with Three Profiles. Lets Say dev,stage,prod. In Every profile I have a Configuration File and There is a Key like this:

client:
   account:
      "acc1":"1"
  

This "acc1" Key has Different Values in Every Profile. So there is Two Questions:

1: How I can store key/values based on profiles?

2: How I can read them in the Application?

Thanks for Your Advice.

1

There are 1 answers

0
ozkanpakdil On

1: How I can store key/values based on profiles?

You do not need to do anything for how to read key/values based on profile, you just need to define the profile in your command line and write application-dev.yml and application.yml for default values then spring will do the rest.

java -jar application.jar --spring.profiles.active=dev 

2: How I can read them in the Application?

Just define those in the ymls and read like

@Value("${propertyname}")
private String abc;

References:

  1. https://stackoverflow.com/a/37043168/175554
  2. https://stackoverflow.com/a/58779322/175554