How to update SpringBoot application configuration at run time without reloading the entire ApplicationContext

I am trying to figure out how I can dynamically update / reload external configuration in a Spring Boot application without restarting the entire application.

Most of the recommendations include reloading the ApplicationContext after changing the external configuration, but this is equivalent to restarting the entire application, so this is actually not so useful.

After reading the SpringBoot reference documentation, I found Chapter 23.7 Secure Access Configuration Properties .

If I understand correctly, this allows you to define simple POJO classes that will contain your application configuration values ​​(external) as attributes.

In theory, at least this scheme can be used to bind beans only once to the desired POJO configuration, and after changing the configuration, simply update the values ​​in the POJO. Components can easily pick up changes the next time they access POJO recipients ...

However, I have not yet been able to figure out how to enable this type of behavior. Is there an obvious way to dynamically update components annotated with @ConfigurationPropertieswhen changing the appropriate configuration?

+4
source share
1 answer

It looks like you are looking for @RefreshScopeone that is provided by Spring Cloud. From Spring Cloud Documentation :

A Spring @Bean, @RefreshScope, . stateful beans, , . , a DataSource , URL- Environment, , , , , . , , - , URL-.

+7

Source: https://habr.com/ru/post/1613334/


All Articles