Spring Config Server with Spring Boot Properties

327 views Asked by At

I am storing application.properties file in my config server. And my client applications are refering config server to download the property files.

Scenario 1:

When i change the value of property server.port in my config server. Can i reflect the changes in my client applicaiton without restarting the application.

1

There are 1 answers

0
Mark Bramnik On

You can use @RefreshScope beans for this purpose, this is not ideal but as close as you can get in config server, this is a pretty advanced thing after all.

So beans marked with this annotations will cause spring to clear the internal cache of the beans / configuration classes upon EnvironmentChangeEvent, then the instance of the bean will be created next time you'll try to call this bean.

To trigger such an event when the config server changes you can either explicitly call the actuator's refresh enpoint or develop your own solution that might be based on some messaging system so that the config server will be a producer of a "change" message and the consumer will be your application.

Now I can't say for sure whether it will work in particular with server.port, I've personally never seen a need to change this property, but for your custom beans this method will do the job.

Here is a good tutorial about this topic