Spring Cloud之Finchley版学习(二十二)-Spring Cloud Config-配置动态刷新

作者: wencst 分类: JAVA,微服务,架构设计 发布时间: 2019-02-28 22:20 阅读: 4,787 次

配置刷新三要素

  • 依赖中有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 端点。

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

如果文章对您有用,扫一下支付宝的红包,不胜感激!

欢迎加入QQ群进行技术交流:656897351(各种技术、招聘、兼职、培训欢迎加入)



Leave a Reply