上一篇博客搭建ConfigClient端寫了configClient端從configServer端獲取到數據,但是它會放到緩存中,不重啓服務是不會重新去configClient獲取的。
configServer端的數據是跟git實時同步的。
在pom中添加一個監控的依賴
<!-- actuator監控中心 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
在配置文件中添加以下內容
management:
endpoints:
web:
exposure:
include: "*"
在獲取配置信息的Bean上面添加刷新註解
@RefreshScope
啓動Eureka,啓動server端,啓動client端
更改git中配置文件的內容
在後面加了一個-edit
在server端訪問文件
http://localhost:8888/test-configClient-sit.properties
數據已更改
訪問client端接口
數據還是更改前的樣子,這是還讀取的緩存中的數據。
在啓動日誌中找到此接口
現在我們使用接口測試工具postman,向http://ip:port/actuator/refresh發送Post請求。表示手動刷新
響應體中有數據,紅框中的內容就是有改動的內容。
現在訪問client端的接口就可以獲取到最新數據,而不用重啓項目。