Java – a better way to update spring boot properties when your application is running

So far, I've seen how to update the spring launch application by changing the properties file itself and then reloading the file, or using the @ refreshscope annotation, or through spring cloud config

I can't find anything directly (such as getenvironment() updateProperty(key,value)).

Is there such a way?

For example, I need to change the logging type of my application to display SQL; My application The properties file contains the following lines: spring jpa. show-sql = false.

But what if I want to set it to true through rest calls when the application is running?

Can you suggest a simpler way? And / or show how to do this specific attribute yourself?

Edit: changes do not need to be reflected in the application Properties file Therefore, when the application is restarted, it will use the original application The properties set in the properties file

Solution

Some answers suggest using spring cloud config server For some people, this may be an overcorrection This answer is exactly what you are looking for How to hot reload properties in Spring Boot and Java EE

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>