Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
434 views
Welcome To Ask or Share your Answers For Others

1 Answer

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()


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...