I am trying to figure out how can I dynamically update/reload externalized configuration in a Spring Boot application without restarting the whole application.
Most
It sounds like you're looking for @RefreshScope
which is provided by Spring Cloud. From the Spring Cloud documentation:
A Spring
@Bean
that is marked as@RefreshScope
will get special treatment when there is a configuration change. This addresses the problem of stateful beans that only get their configuration injected when they are initialized. For instance if aDataSource
has open connections when the database URL is changed via theEnvironment
, we probably want the holders of those connections to be able to complete what they are doing. Then the next time someone borrows a connection from the pool he gets one with the new URL.