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

Categories

0 votes
423 views
in Technique[技术] by (71.8m points)

Update property in spring environment in java code

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

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

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...