先解釋下爲什麼突然斷更半個月:
- 正月初三 - 正月十二:父親肺氣腫住院;母親肺炎,也要掛水,故請假照顧。
- 正月十四 - 正月二十:奶奶摔了一跤,突然離世…老家有守夜、辦喪的習俗,請假事喪。
總之,2019開局很不順利……Anyway,今天開工,今天恢復更新。
配置刷新三要素
-
依賴中有
spring-boot-starter-actuator
-
添加如下配置,暴露
/actuator/refresh
端點:management: endpoints: web: exposure: include: refresh
-
待刷新的配置屬性所在的類上添加了
@RefreshScope
註解 ,例如:@RestController @RefreshScope public class ConfigClientController { @Value("${profile}") private String profile; @GetMapping("/profile") public String hello() { return this.profile; } }
這樣,修改profile
配置後,只需嚮應用的/actuator/refresh
端點發送POST請求,即可刷新該屬性。例如:
curl -X POST http://localhost:8081/actuator/refresh
自動刷新、批量刷新-Spring Cloud Bus
參考文檔:<http://www.itmuch.com/spring-cloud/spring-cloud-bus-auto-refresh-configuration/>
引入Cloud Bus後,就會多一個/actuator/bus-refresh
端點
本文首發
<http://www.itmuch.com/spring-cloud/finchley-22/>