nacos icon indicating copy to clipboard operation
nacos copied to clipboard

nacos 配置中心刷新数据 不生效

Open key1012 opened this issue 5 years ago • 37 comments

使用配置中心,修改数据后不生效,控制台监听到了修改动作,[notify-listener] time cost=1ms in ClientWorker, dataId=

Using the configuration center, the data modification does not take effect. The console monitors the modification action, [notify listener] time cost = 1ms in clientworker, dataid.=

key1012 avatar Oct 23 '19 01:10 key1012

请看下{user.home}/logs/nacos/config.log里面是否有收到推送?

nkorange avatar Nov 10 '19 15:11 nkorange

Whether to use spring-cloud

chuntaojun avatar May 22 '20 03:05 chuntaojun

我也是这样的问题 控制台打印了推送的新的配置信息,但是没有办法实现自动刷新 springcloud工程 已添加@RefreshScope注解

wangshiminwork avatar Jul 04 '20 07:07 wangshiminwork

这个问题大家是如何解决的

Liesport758 avatar Sep 02 '20 08:09 Liesport758

我控制台也收到了刷新的信息 但是不生效 Refresh keys changed: [mybatis-plus.mapper-locations, spring.datasource.password]

1061691343 avatar Nov 14 '20 01:11 1061691343

参考 将配置映射到实体对象,上面添加@RefreshScope 可以实现动态刷新

用@Value注入的配置文件无法刷新。

@RefreshScope @ConfigurationProperties(prefix = "user") @Component @Data public class User { private String name; }

zzx131 avatar Dec 07 '20 07:12 zzx131

参考 将配置映射到实体对象,上面添加@RefreshScope 可以实现动态刷新

用@value注入的配置文件无法刷新。

@RefreshScope @ConfigurationProperties(prefix = "user") @component @DaTa public class User { private String name; }

试了,也不行

mrwlei avatar Dec 11 '20 10:12 mrwlei

image image 当我nacos控制台修改年龄后,日志已打印出最新修改的值,但是原来注入到spring的值,没有刷新 18:19:58.375 [com.alibaba.nacos.client.Worker.longPolling.fixed-nacos.ehking.com-e00d9625-39fa-43ea-8d54-d29bb1181078] INFO c.a.n.c.c.i.ClientWorker - [parseUpdateDataIdResponse,422] - [fixed-nacos.ehking.com-e00d9625-39fa-43ea-8d54-d29bb1181078] [polling-resp] config changed. dataId=mmtax.properties, group=DEFAULT_GROUP, tenant=e00d9625-39fa-43ea-8d54-d29bb1181078 18:19:58.455 [com.alibaba.nacos.client.Worker.longPolling.fixed-nacos.ehking.com-e00d9625-39fa-43ea-8d54-d29bb1181078] INFO c.a.n.c.c.i.ClientWorker - [run,526] - [fixed-nacos.ehking.com-e00d9625-39fa-43ea-8d54-d29bb1181078] [data-received] dataId=mmtax.properties, group=DEFAULT_GROUP, tenant=e00d9625-39fa-43ea-8d54-d29bb1181078, md5=6cdc1dcf17373dc1b07b972e7d657f60, content=user.name=wanglei user.age=19

mrwlei avatar Dec 11 '20 10:12 mrwlei

我试过 ,可以的呀在属性上加value("${****}"),在该属性的类上加注解@RefreshScope 把配置信息写在nacos配置中心就好啦,之后改变值就会自动刷新,不需要重启项目

------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月11日(星期五) 晚上6:11 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960)

参考 将配置映射到实体对象,上面添加@RefreshScope 可以实现动态刷新

用@value注入的配置文件无法刷新。

@RefreshScope @ConfigurationProperties(prefix = "user") @component @DaTa public class User { private String name; }

试了,也不行

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

1061691343 avatar Dec 12 '20 00:12 1061691343

你好,不知道您是如何配置的呀  给不了答复

------------------ 原始邮件 ------------------ 发件人: "zzx131"<[email protected]>; 发送时间: 2020年12月7日(星期一) 下午3:23 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960)

这个问题解决了吗?今天遇到这个问题,没有重新加载配置中心的配置,版本spring-cloud-starter-alibaba-nacos-config -2.2.1 Listener listener = listenerMap.computeIfAbsent(key, lst -> new AbstractSharedListener() { @override public void innerReceive(String dataId, String group, String configInfo) { refreshCountIncrement(); nacosRefreshHistory.addRefreshRecord(dataId, group, configInfo); // todo feature: support single refresh for listening applicationContext.publishEvent( new RefreshEvent(this, null, "Refresh Nacos config")); if (log.isDebugEnabled()) { log.debug(String.format( "Refresh Nacos config group=%s,dataId=%s,configInfo=%s", group, dataId, configInfo)); } } });

— 您收到评论是因为您对此发表了评论。 直接回复此电子邮件,在GitHub上查看,或取消订阅。

1061691343 avatar Dec 12 '20 00:12 1061691343

我试过 ,可以的呀在属性上加value("${****}"),在该属性的类上加注解@RefreshScope 把配置信息写在nacos配置中心就好啦,之后改变值就会自动刷新,不需要重启项目 ------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月11日(星期五) 晚上6:11 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960) 参考 将配置映射到实体对象,上面添加@RefreshScope 可以实现动态刷新 用@value注入的配置文件无法刷新。 @RefreshScope @ConfigurationProperties(prefix = "user") @component @DaTa public class User { private String name; } 试了,也不行 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

你用的nacos是哪个版本的?

mrwlei avatar Dec 14 '20 01:12 mrwlei

1061691343   直接加qq聊吧  邮件发的很慢

------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月14日(星期一) 上午9:45 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960)

我试过 ,可以的呀在属性上加value("${****}"),在该属性的类上加注解@RefreshScope 把配置信息写在nacos配置中心就好啦,之后改变值就会自动刷新,不需要重启项目 … ------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月11日(星期五) 晚上6:11 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960) 参考 将配置映射到实体对象,上面添加@RefreshScope 可以实现动态刷新 用@value注入的配置文件无法刷新。 @RefreshScope @ConfigurationProperties(prefix = "user") @component @DaTa public class User { private String name; } 试了,也不行 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

你用的nacos是哪个版本的?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

1061691343 avatar Dec 14 '20 05:12 1061691343

1061691343   直接加qq聊吧  邮件发的很慢 ------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月14日(星期一) 上午9:45 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960) 我试过 ,可以的呀在属性上加value("${****}"),在该属性的类上加注解@RefreshScope 把配置信息写在nacos配置中心就好啦,之后改变值就会自动刷新,不需要重启项目 … ------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月11日(星期五) 晚上6:11 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960) 参考 将配置映射到实体对象,上面添加@RefreshScope 可以实现动态刷新 用@value注入的配置文件无法刷新。 @RefreshScope @ConfigurationProperties(prefix = "user") @component @DaTa public class User { private String name; } 试了,也不行 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. 你用的nacos是哪个版本的? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

换了一个版本,可以了...

mrwlei avatar Dec 14 '20 06:12 mrwlei

ok

------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月14日(星期一) 下午2:29 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960)

1061691343   直接加qq聊吧  邮件发的很慢 … ------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月14日(星期一) 上午9:45 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960) 我试过 ,可以的呀在属性上加value("${****}"),在该属性的类上加注解@RefreshScope 把配置信息写在nacos配置中心就好啦,之后改变值就会自动刷新,不需要重启项目 … ------------------ 原始邮件 ------------------ 发件人: "王雷"<[email protected]>; 发送时间: 2020年12月11日(星期五) 晚上6:11 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960) 参考 将配置映射到实体对象,上面添加@RefreshScope 可以实现动态刷新 用@value注入的配置文件无法刷新。 @RefreshScope @ConfigurationProperties(prefix = "user") @component @DaTa public class User { private String name; } 试了,也不行 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. 你用的nacos是哪个版本的? — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

换了一个版本,可以了...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

1061691343 avatar Dec 14 '20 06:12 1061691343

@mrwlei 你用的哪个版本?

huwb13329901681 avatar Dec 16 '20 06:12 huwb13329901681

1.2.1

------------------ 原始邮件 ------------------ 发件人: "alibaba/nacos" <[email protected]>; 发送时间: 2020年12月16日(星期三) 下午2:19 收件人: "alibaba/nacos"<[email protected]>; 抄送: "蔡呈杰"<[email protected]>;"Comment"<[email protected]>; 主题: Re: [alibaba/nacos] nacos 配置中心刷新数据 不生效 (#1960)

@mrwlei 你用的哪个版本?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

1061691343 avatar Dec 16 '20 06:12 1061691343

这个好像主要是在用到@Value的类上面加上@RefreshScope注解,另外可能是springboot的版本跟nacos-config版本差异大(我springboot2.3.4,nacos-config2.2.3没问题)

chenmu5241 avatar Jan 03 '21 15:01 chenmu5241

在ideal里可以生效,但打成jar运行就只能监听到更新事件,但无法生效 o.s.c.e.event.RefreshEventListener : Refresh keys changed: []
springboot2.3.4,nacos-config2.2.3

yueyihan avatar Jan 07 '21 08:01 yueyihan

spring cloud 版本:2.2.0.RELEASE nacos 版本:2.2.0.RELEASE

在idea内无法刷新配置中心数据,以jar运行可以正常刷新。

mfkwfc avatar Jan 19 '21 07:01 mfkwfc

我升级了最新版本 1.4.1 好像是@RefreshScope和@Value 必须同时使用的时候才能热加载实时数据。但是以前1.3.0的时候 没有这个限制,不知道是不是又是一个新的bug。如果按照现在这个规矩 两个必须一起用才生效,这也太麻烦了吧!!!

WTroy avatar Feb 01 '21 06:02 WTroy

我升级了最新版本 1.4.1 好像是@RefreshScope和@value 必须同时使用的时候才能热加载实时数据。但是以前1.3.0的时候 没有这个限制,不知道是不是又是一个新的bug。如果按照现在这个规矩 两个必须一起用才生效,这也太麻烦了吧!!!


我也是1.4.1升级后发现这个问题,今天找半天,,。我的代码springcloud版本没做任何改动,推测nacos1.4.1引入的问题?

610983691 avatar Feb 05 '21 07:02 610983691

你的配置要是在共享配置文件,要如下方式启用刷新,参考:https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html

cloud:
   nacos:
     config:
       # 配置中心地址
       server-addr: 192.168.88.5:8848
       # 配置文件格式
       file-extension: yaml
       # 共享配置
       shared-configs:
         - data-id : demo-default-${spring.profiles.active}.yaml
           # 让扩展配置刷新
           refresh : true

xiaosan666 avatar Mar 10 '21 03:03 xiaosan666

今天也有遇到这个情况,不过我解决了。很大概率是因为项目启动后因为某些原因无法完成ApplicationReadyEvent事件,导致了NacosContextRefresher 的监听没法执行ready事件。

chouway avatar Apr 14 '21 06:04 chouway

今天也有遇到这个情况,不过我解决了。很大概率是因为项目启动后因为某些原因无法完成ApplicationReadyEvent事件,导致了NacosContextRefresher 的监听没法执行ready事件。

请问一下您是怎么解决的,谢谢!

azi03 avatar Jun 03 '21 12:06 azi03

今天也有遇到这个情况,不过我解决了。很大概率是因为项目启动后因为某些原因无法完成ApplicationReadyEvent事件,导致了NacosContextRefresher 的监听没法执行ready事件。

请问一下您是怎么解决的,谢谢!

@EnableConfigurationProperties({xx.class}),添加这个注解在Application类下,就可以动态更新。

llooper-dev avatar Jun 30 '21 07:06 llooper-dev

我也遇到这问题了。。。无语

JackCaptain1015 avatar Oct 13 '21 07:10 JackCaptain1015

刚解决这个问题,我是因为bootstrap.properties没起作用,添加相关依赖就可以了。可以看下这篇博客:Nacos配置中心不起作用解决方案

HeyWeCome avatar Nov 09 '21 07:11 HeyWeCome

谢谢你的来信蔡呈杰已经收到辛苦了~

1061691343 avatar Dec 11 '21 12:12 1061691343

在ideal里可以生效,但打成jar运行就只能监听到更新事件,但无法生效 o.s.c.e.event.RefreshEventListener : Refresh keys changed: [] springboot2.3.4,nacos-config2.2.3

我遇到的问题和你一样的,有初步怀疑是其他依赖导致的

xiaohaibaba avatar Dec 11 '21 12:12 xiaohaibaba

使用配置中心,修改数据后不生效,控制台监听到了修改动作,[notify-listener] time cost=1ms in ClientWorker, dataId=

Using the configuration center, the data modification does not take effect. The console monitors the modification action, [notify listener] time cost = 1ms in clientworker, dataid.=

bootstrap.yml 配置的 application.name + "." + cloud.nacos.config.file-extension 属性和 nacos 的 Data ID 需要保持一致

spring:
  application:
    # 必须把name属性从application.yml迁移过来,否则无法动态刷新
    name: coupon-customer-serv

  cloud:
    nacos:
      config:
        # prefix: 文件名前缀,默认是spring.application.name
        file-extension: yml

还有就是 @Value 和 @RefreshScope 两个注解搭配使用,@RefreshScope 的作用是使用 Nacos 动态刷新的值来替换 Spring Context

Nacos 版本是 1.4.1

HelloJava404 avatar May 17 '22 17:05 HelloJava404