0

I want to be able to load properties from a yaml file and then set a property dynamically everytime the application starts up. The active profile determines the source.system properties below, different per profile as is the back-end.url

yaml looks like this:

source:
  system:
    google:
      uri: https://www.google.com
      user: testUser
      value: {dynamically_set_property}
source:
  system:
    facebook:
      uri: https://www.facebook.com
      user: testUser
      value: {dynamically_set_property}
back-end:
   url: /version1/
     

There is some UTIL class that i have written which takes in the properties above and then uses them to set the dynamic property.

@ConfigurationProperties(prefix=source.system)
public class MyUtil {

private Map<String, SourceSystem> sourceSystems;

//doSomething with the source system
public void setDynamicProperty(String value) {
   SourceSystem source = sourceSystems.get(value);
   //check back-end.url and set source.value
}

}

So on startup when the application runs, I want to set "dynamically_set_property" but to do that I need to have access to the back-end.url property. I have looked at DynamicPropertyResolver but that doesn't give me access to the "back-end.url" property in the static method implementation.

Is implementing EnvironmentAware the only other option? Ideally what I would like is some configuration bean loading before any spring core, 3rd party or other annotated beans within my application and it would run some pre-processing so set the dynamically_set_property.

3
  • 1
    Just use a config file per profile : application.yaml, application-dev.yaml, application-prod.yaml, ... Another tip : every profile file inherits the values from application.yaml, so update only the properties you need to Commented May 9, 2022 at 10:12
  • I am doing that already, I think you've missed the question, I want to dymanically resolve a property at runtime using some code Commented May 9, 2022 at 10:14
  • You could set up the dynamic values in an environment variable, then use the @Value annotation : stackoverflow.com/questions/44803211/… Commented May 11, 2022 at 13:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.