1

In my spring boot application, scenario: a property in application.properties is given. I want to update the property in the environment in the same application in java code.

Note: I do not want to use Spring config server, because I do not want to refresh the property manually.

I need a solution in which I could somehow, modify the properties set in the environment at runtime in java code.

Any pointers would be appreciated.

Ankit garg
  • 71
  • 6

1 Answers1

1

Have you tried this?

System.setProperty("key","value")

I believe at runtime you can use this to change the environment values.

Be careful with the placement of the above statement. @Value annotations will be evaluated by BeanPostProcessors during context initialization. You would surely get the updated system properties by autowiring Environment and use environment.getProperty()

ameenhere
  • 2,203
  • 21
  • 36