nacos属性自动刷新的问题

关于属性自动刷新

  • 两种方案,参考https://juejin.cn/post/6876810580993245197

    1. @RefreshScope + @Value

    2. @RefreshScope + @ConfigurationProperties

  • 问题:在nacos上修改配置文件,程序成功刷新,但刷新一次后,报错longPolling Error,导致后续的修改无法刷新到。解决方案:将 2.2.4版本升级到2.2.5

    		<!-- nacos 服务注册与发现 -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
                <version>2.2.5.RELEASE</version>
            </dependency>
    
            <!-- nacos 配置中心 -->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
                <version>2.2.5.RELEASE</version>
            </dependency>
    
  • 只自动刷新nacos默认加载的配置,如

    ${spring.application.name}.${file-extension:properties}

    ${spring.application.name}-${profile}.${file-extension:properties}

    而对于其他的自定义加载的配置,需要额外配置refresh:true,如下

    spring:
      profiles:
        active: dev
      application:
        name: liveness
    
      cloud:
        nacos:
          server-addr: 127.0.0.1:8848  
          username: nacos
          password: nacos
          discovery:
            namespace: xxxx
            group: liveness
          config:
            namespace: xxxx
            group: liveness
            file-extension: yml
            extension-configs:
            - dataId: ${spring.profiles.active}-${spring.application.name}-database.yml
              group: liveness
              refresh: true  # 手动开启自动刷新
            - dataId: ${spring.profiles.active}-${spring.application.name}-redis.yml
              group: liveness
              refresh: true
            - dataId: ${spring.profiles.active}-${spring.application.name}-properties.yml
              group: liveness
              refresh: true
            refresh-enabled: true
    
    
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值