温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-07-08 17:12:36 来源:网络 阅读:295 作者:lilizhou2008 栏目:编程语言

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

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

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

干货分享

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI