Sometimes some parameters in the configuration center need to be modified. How can we achieve real-time effect without restarting?
Add dependencies
<dependencies> ... <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> ...</dependencies>
spring-boot-starter-actuator: The /refresh (POST request) endpoint of this module can refresh the configuration. For more information, please refer to the Spring Boot series articles.
Prerequisites for effective
Add @RefreshScope annotation on the bean that needs to be refreshed.
@RefreshScope@RestControllerpublic class TestController { @Value("${username}") private String username;...When the configuration changes, the bean marked @RefreshScope will be specially processed to take effect.
Extended Issue
If there are fewer projects and fewer configurations, you can manually refresh the configuration through /refresh. If the project is more complicated, this will definitely not work. Spring Cloud Bus message bus can solve the real dynamic refresh of configuration modification.
Summarize
The above is the Spring Cloud dynamic refresh configuration information introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!