Reputation: 91
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.
Upvotes: 9
Views: 32048
Reputation: 5105
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.
Upvotes: 0
Reputation: 131
Pass SPRING_PROFILES_ACTIVE
as environment variable to Spring Boot app instead of declaring it in yaml and hard coding it in configuration file. The app picks the corresponding yaml based on the profile.
How to pass spring profile as parameter to spring boot app
Upvotes: 13