SrpingCloud 之SrpingCloud config分布式配置中心实时刷新
生活随笔
收集整理的這篇文章主要介紹了
SrpingCloud 之SrpingCloud config分布式配置中心实时刷新
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
默認情況下是不能及時獲取變更的配置文件信息
Spring Cloud分布式配置中心可以采用手動或者自動刷新
?1、手動需要人工調用接口? ?監控中心
?2、消息總線實時通知? springbus
?
動態刷新數據
在SpringCloud中有手動刷新配置文件和實時刷新配置文件兩種方式。
手動方式采用actuator端點刷新數據
實時刷新采用SpringCloud Bus消息總線
?
?
??
actuator端點刷新數據
在config clientr引入?
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId> </dependency>
yml中開啟監控斷點
management:endpoints:web:exposure:include: "*"同時在controller加 @RefreshScope
package com.toov5.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;@RestController @RefreshScope public class TestController {@Value("${motto}") //配置的keyprivate String motto;@RequestMapping("/getMotto")public String getMotto() {return motto;} }?
開啟: 修改git上的配置文件信息
必須要用post請求!
http://127.0.0.1:8882/actuator/refresh
?
成功!
?每個客戶端都有監聽,效果不是很好這樣的方式。手動刷新比較好一些。改完了自己手動刷新下 post 調用一下
高級的spring cloud bus: https://www.cnblogs.com/toov5/p/10293755.html?
轉載于:https://www.cnblogs.com/toov5/p/9966822.html
總結
以上是生活随笔為你收集整理的SrpingCloud 之SrpingCloud config分布式配置中心实时刷新的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 116-数学运算符更多的使用
- 下一篇: sql 2008数据库日志清理(转)