SpringCloud Config手動刷新及自動刷新


1、Config手動刷新
a、使用@RefreshScope注解

import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; /** * 這邊的@RefreshScope注解不能少,否則即使調用/refresh,配置也不會刷新 */ @RestController @RefreshScope public class ConfigClientController { @Value("${env}") private String env; @Value("${password}") private String password; @Value("${username}") private String username; @GetMapping("/config/profile") public String hello() { return this.env+","+this.password+","+this.username; } }

 

b、post請求config客戶端的/refresh端點
http://localhost:6062/refresh

再次訪問http://localhost:6062/config/profile,發現配置文件為最新配置。

2、Config自動刷新
1、WebHooks動態刷新

2、spring-cloud-bus動態刷新


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM