Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

声明式动态刷新不生效 #3747

Closed
Mredust opened this issue May 24, 2024 · 6 comments
Closed

声明式动态刷新不生效 #3747

Mredust opened this issue May 24, 2024 · 6 comments
Labels
area/nacos spring cloud alibaba nacos kind/question stale

Comments

@Mredust
Copy link

Mredust commented May 24, 2024

版本:boot:2.4.2 cloud:2020.0.1 cloud alibaba:2021.1 nacos:1.4.1
spring:
application:
name: nacos-demo
profiles:
active: dev
cloud:
nacos:
server-addr: 192.168.91.131:8848
discovery:
namespace: ${spring.profiles.active}
group: nacos-demo
cluster-name: gz
config:
namespace: ${spring.profiles.active}
group: nacos-demo
file-extension: yaml
refresh-enabled: true
extension-configs:
- data-id: nacos-demo-api-${spring.profiles.active}.yaml
group: nacos-demo
refresh: true
- data-id: nacos-demo-service-${spring.profiles.active}.yaml
group: nacos-demo
refresh: true
shared-configs:
- data-id: common-${spring.profiles.active}.yaml
group: common-dev
refresh: true

对动态刷新测试过@RefreshScope是可以的,换成声明式的refresh-enabled: true就不行。在nacos服务配置修改文件并发布后控制台是有日志说明我修改过文件,最后请求时还是之前的配置信息,但是重启后配置信息是重新读取了。请问这个声明式的配置是可以用的吗

@yuluo-yx
Copy link
Collaborator

yuluo-yx commented May 24, 2024

/kind question
/area nacos

@github-actions github-actions bot added kind/question area/nacos spring cloud alibaba nacos labels May 24, 2024
@ruansheng8
Copy link
Collaborator

基于 @ConfigurationProperties 声明的属性配置类,可以实时动态刷新(refresh-enabled 默认为开启状态),如果使用 Spring 中的 @Value 方式,在类上添加 @RefreshScope 也可以实现动态刷新。

如果你的动态刷新功能失效,可以贴一下你代码中具体是如何使用的

@Mredust
Copy link
Author

Mredust commented May 28, 2024

基于 @ConfigurationProperties 声明的属性配置类,可以实时动态刷新(refresh-enabled 默认为开启状态),如果使用 Spring 中的 @Value 方式,在类上添加 @RefreshScope 也可以实现动态刷新。

如果你的动态刷新功能失效,可以贴一下你代码中具体是如何使用的

如果不使用 @ConfigurationProperties 、@RefreshScope和 @NacosValue ,单单只是使用 refresh-enabled 能否生效。但是我用了后发现不生效并不会实时刷新
image
image
image

@ruansheng8
Copy link
Collaborator

ruansheng8 commented May 28, 2024

@Mredust@Value 必须配合 @RefreshScope 一起使用才行实现动态刷新,这个机制和 Spring Cloud 官方的定义保持一致,因为有的场景是希望启动后值就固定,不允许动态刷新,所以需要动态刷新的场景需要手动添加 @RefreshScope

@Mredust
Copy link
Author

Mredust commented May 28, 2024

@Mredust@Value 必须配合 @RefreshScope 一起使用才行实现动态刷新,这个机制和 Spring Cloud 官方的定义保持一致,因为有的场景是希望启动后值就固定,不允许动态刷新,所以需要动态刷新的场景需要手动添加 @RefreshScope

明白了,感谢感谢

Copy link

This issue has been open 30 days with no activity. This will be closed in 7 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/nacos spring cloud alibaba nacos kind/question stale
Projects
None yet
Development

No branches or pull requests

3 participants