SpringCloud整合config刷新

简介

默认情况下是不能获取实时变更的配置文件信息,对于config server是实时,而对于config client 是存在缓存的。
修改配置文件config-client-sit.properties如下:
image.png
config server 访问:http://localhost:8888/config-client-sit.properties
image.png
立即拉去到更新数据。
config client 访问:http://localhost:8883/getBabainfo
image.png
不能拉取到更新数据!

解决方案

  1. 手动刷新,需要人工调用接口,读取配置文件(监控中心)
  2. 自动刷新,消息总线进行实时通知,springbus

这里我们先介绍第一种方式

配置监控中心

springcloud-config-client 中引入actuator监控中心:



 org.springframework.boot
 spring-boot-starter-actuator

springcloud-config-client 配置文件开启所有端点

####开启所有端点
management:
  endpoints:
    web:
      exposure:
        include: "*"

image.png

并且在调用配置文件的类上面加上 @RefreshScope注解,才能生效
image.png

重启服务

image.png

修改 config-client-sit.properties配置文件

image.png
Config Service 服务直接可以获取最新配置
image.png
Config Client 需要先手动post调用 localhost:8883/actuator/refresh后才能获取最新数据:
image.png

你可能感兴趣的:(javaspringboot)