How to load the SPRING_PROFILES_ACTIVE value in the client service dynamically?

Viewed 14607

I am new to spring and creating a spring cloud config service. I have successfully created the configuration service where all the configurations are there. In my client service(this will fetch all the necessary configurations from the configuration service) I need to fetch the configurations depending on the SPRING_PROFILES_ACTIVE value which is defined in the manifest file. There are multiple manifest files in the client service and each has its own SPRING_PROFILES_ACTIVE value. Currently I am using @ConfigurationProperties(prefix="profile_name") i.e manually defining the "profile_name". But, I want to make it dynamically i.e depending on the value of SPRING_PROFILES_ACTIVE the value should be fetched from configuration service. Can anyone please suggest me how to load the value dynamically.

Thanks in advance.

2 Answers

depending on the value of SPRING_PROFILES_ACTIVE the value should be fetched from configuration service.

If I understand correctly, you are trying to get configuration from a Config Server based on the active profiles in the client app. Spring Cloud Config Client does this automatically, as described in the documentation. For example, if the client app has spring.profiles.active=profile1,profile2, then at boostrapping the config client will make requests to the Config Server with URLs like

https://my-config-server.example.com/sample-app/profile1/master
https://my-config-server.example.com/sample-app/profile2/master

and load the response from each request into a property source in the client app.

Related