apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
28.95k stars 10.19k forks source link

删除配置的时候,希望能够通过AutoUpdateConfigChangeListener将SpringValue对应的字段置为null #5053

Closed davisrain closed 5 months ago

davisrain commented 6 months ago

现在遇到的问题是 通过注解注入了一个apollo的配置到bean的字段中,当我从apollo删除这个配置的时候,我希望对应的字段能更新为null。但是现在AutoUpdateConfigChangeListener能够监听到这个DELETE类型的变化,在解析占位符的阶段必定会报错,因为此时PropertySource中已经不存在对应的属性了,并且默认的占位符解析是严格模式,所以会抛出异常,导致bean中字段的值仍然是删除之前的原值。 image image

dosubot[bot] commented 6 months ago

🤖

Hello @davisrain! 👋 I'm Dosu, an AI bot here to help you with your Apollo-related inquiries, bugs, and contributions. While we wait for a human maintainer, feel free to shoot me any questions or concerns you might have. Let's tackle this together! 🚀

根据我找到的相关问题使用EnvironmentChangeEvent在特定场景下无法刷新ConfigurationProperties注解,这个问题已经在Apollo的某个版本中得到了解决。

在这个问题中,当Apollo配置发生变化时,Spring的@ConfigurationProperties注解可能无法正确地刷新配置。这是因为Apollo在处理配置变化时,会触发一个EnvironmentChangeEvent,但是Spring可能在处理这个事件时,无法正确地刷新@ConfigurationProperties注解的配置。

解决这个问题的方法是,当Apollo配置发生变化时,除了触发EnvironmentChangeEvent,还需要手动调用ConfigurationPropertiesRebinder.rebind()方法来强制刷新@ConfigurationProperties注解的配置。

这个解决方案可能对你的问题有所帮助。你可以尝试在Apollo配置发生变化时,手动调用ConfigurationPropertiesRebinder.rebind()方法来强制刷新配置。

如果你需要更多的帮助,或者这个解决方案无法解决你的问题,请提供更多的信息,我会尽我所能来帮助你。

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

nobodyiam commented 6 months ago

这个是符合预期的,如果要提供默认值的话,可以用 spring 的语法,类似 @Value("${batch:100}")

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 5 months ago

This issue has been automatically closed because it has not had activity in the last 7 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.