SpringCloud配置文件刷新之@RefreshScope

背景
当遇到生产环境配置参数需要调整,但又没有配置中心的支持的情况下,只能重启应用以加载新参数,可能会影响业务系统运行,太暴力不优雅;
@RefreshScope注解能帮助我们做局部的参数刷新,但侵入性较强,需要开发阶段提前预知可能的刷新点,并且该注解底层是依赖于cglib进行代理的,所以不要掉入cglib的坑,出现刷了也不更新情况;
常规的操作姿势大致有下面5个步骤;

操作指南
1、加依赖

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

2、加yml配置

management:
  security:
    enabled: false
  context-path: /
spring:
  application:
    name: mc-notify-proc
  cloud:
    config:
       uri: ${CONFIG_URL:http://config-6c6e748485ba4979955467bf3c372.cs.xxx.cn}  #${config-6c6e748485ba4979955467bf3c372.za23-config.svc.cluster.local:http://config-6c6e748485ba4979955467bf3c372.cs.xxx.cn}

3、加注解

@Component
@Slf4j
@RefreshScope
public class YstHttpProxySms {

    @Value("${ystServicesSmsTokenUrl}")
    private String ystServicesTokenUrl;

    @Value("${ystServicesSmsUrl}")
    private String ystServicesSmsUrl;

    @Value("${accessKey}")
    private String accessKey;

    @Value("${secretKey}")
    private String secretKey;

    @Value("${refreshMin}")
    private int refreshMin;

4、修改参数
修改配置文件

5、发送刷新请求

http://localhost:8081/actuator/refresh

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值