跟我学Spring Cloud(Finchley版)-22-Spring Cloud Config-配置动态刷新

先解释下为什么突然断更半个月:

  • 正月初三 - 正月十二:父亲肺气肿住院;母亲肺炎,也要挂水,故请假照顾。
  • 正月十四 - 正月二十:奶奶摔了一跤,突然离世…老家有守夜、办丧的习俗,请假事丧。

总之,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/

干货分享

全是干货!

转载于:https://my.oschina.net/eacdy/blog/3017535

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值