SrpingCloud 之SrpingCloud config分布式配置中心实时刷新

SrpingCloud 之SrpingCloud config分布式配置中心实时刷新

默认情况下是不能及时获取变更的配置文件信息

Spring Cloud分布式配置中心可以采用手动或者自动刷新

 1、手动需要人工调用接口   监控中心

 2、消息总线实时通知  springbus

 

动态刷新数据

在SpringCloud中有手动刷新配置文件和实时刷新配置文件两种方式。

手动方式采用actuator端点刷新数据

实时刷新采用SpringCloud Bus消息总线

 

 

  

actuator端点刷新数据

在config clientr引入 

      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency>

  

yml中开启监控断点

management:
  endpoints:
    web:
      exposure:
        include: "*"

 同时在controller加 @RefreshScope 

package com.toov5.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class TestController {
    @Value("${motto}")   //配置的key
  private String motto;
    
    @RequestMapping("/getMotto")
    public String getMotto() {
        return motto;
    }
}

 

开启: 修改git上的配置文件信息

必须要用post请求!
 

http://127.0.0.1:8882/actuator/refresh

 

成功!

 每个客户端都有监听,效果不是很好这样的方式。手动刷新比较好一些。改完了自己手动刷新下 post 调用一下

高级的spring cloud bus: https://www.cnblogs.com/toov5/p/10293755.html 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值