-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
在配置中心删除某项配置之后无法将这项配置更新为空值 #12690
Comments
我测试是生效了的, 你配置类有使用 |
好吧,是我不严谨了。我测试了在配置类上使用以及不使用
根据测试结果来看,似乎并不是nacos的问题🤐? |
那就奇怪了 使用 |
|
不加@RefreshScope刷新不了哦,我这边刚好有个demo测试了一下,nacos是2.4.2,spring-cloud-starter-alibaba-nacos-config是2023.0.1.2 |
但是实际上的实现逻辑也是需要加上注解才能动态刷新, 官方文档也提到了我本地测试也是这样, 我奇怪的是居然没加可以实现动态刷新. |
|
|
我们先对齐一下我们的问题复现demo吧😂
@Data
@Configuration
@ConfigurationProperties(prefix = "test")
public class TestConfig {
private String config;
}
@Component
@RequiredArgsConstructor
public class TestConfigPrinter implements CommandLineRunner {
private final TestConfig testConfig;
@Override
public void run(String... args) throws Exception {
new Thread(() -> {
for (int i = 0; i < 1000; i++) {
System.out.println("测试配置:" + testConfig.getConfig());
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}).start();
}
} 可以依次:将 |
是的 我看了一下确实, 我测试用的 |
看了一下大概逻辑是 |
|
是的👍所以这个问题该不该修复呢?我感觉还是把值设置为null会合理一些,和 |
这个不是问题吧, 首先这两个注解是 |
我会觉得这是个问题,要么不加 |
看了一下应该是 |
好的,非常感谢👍 |
Describe the bug
例如,在配置中心上有一项配置:
如果把这项配置完全删除掉,程序中读取到的
testConfig
值还是测试配置1,但是期望的testConfig
值应该是null。从程序的日志中可以看到nacos-client拿到了变动后的配置,并且准确地报告了是
test-config
这个配置项有变更。我大概了解配置动态刷新的原理:拿到变更后的配置,将其中的配置项与程序当前的配置项相比较,如果不相等则刷新对应的配置项的值。是否是因为变更后的配置中test-config
这个配置项被删除掉了,导致无法和程序的值进行比较,所以没有更新程序中的值呢?我觉得删除配置项这个动作,在大部分情况下是期望将这个配置项更新为null或者使用默认值(如果有默认值的话),所以我觉得当前的处理不太符合使用者的直觉,很大可能会造成隐患。
我在这个仓库的issues中找到了一个类似的问题:#11170 ,但它目前是closed状态。我现在还无法确定这是nacos的问题,还是spring cloud的问题(因为我当前使用的依赖是
spring-cloud-starter-alibaba-nacos-config
),所以我提了这个issue来寻找一下答案以及后续的处理。期待回复~Expected behavior
删除掉配置中心上的配置项之后,程序中的对应配置项应该刷新为null或者默认值,或者其他更好的处理
Actually behavior
实际上,目前删除掉配置中心上的配置项之后,程序中的对应配置项没有任何变化,还保留着最后一次生效的值
How to Reproduce
使用
spring-cloud-starter-alibaba-nacos-config:2023.0.1.0
按照上述描述去操作即可复现Desktop (please complete the following information):
Additional context
nothing
The text was updated successfully, but these errors were encountered: