刷新外部罐子

发布于 2025-01-29 16:42:37 字数 150 浏览 4 评论 0原文

当有配置更改时,我正在使用Spring-Cloud-Starter来刷新豆类。它对我控制的豆类的工作原理。如果某些豆类属于外部罐子,我也希望在有配置更改时刷新它们,是否可以这样做?这与使用配置创建但可能没有@refreshscope注释的自动配置豆更相关。

I am using spring-cloud-starter for refreshing the beans when there is a config change. It works as expected for beans that I have control over. If there are certain beans that belong to an external jar and I want them to be refreshed as well when there is a config change, is it possible to do that? This is more relevant for AutoConfiguration beans that gets created using configs but might not have @RefreshScope annotated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白芷 2025-02-05 16:42:37

@refreshscope并不是唯一必须在环境更改事件上重新定位bean的指标。还有@ConfigurationProperties - 通过此注释绑定到环境的任何bean也将刷新。

如果您都不适用于您的情况,并且由于某种原因仍然要刷新外部豆类,则可以通过创建Environment ChangeEvent事件侦听器来明确执行此操作,该 tastroe 会破坏并初始化所需的bean。为此,请看一下org.springframework.cloud.context.properties.configurationpropertiesrebinder来自spring> spring> spring-cloud-context模块。

@RefreshScope is not the only indicator that a bean has to be reinitialized upon the environment change event. There's also @ConfigurationProperties - any beans that were bound to environment via this annotation will also be refreshed.

If neither is applicable to your case and still for some reason you'd like to refresh external beans, you can do this explicitly by creating an EnvironmentChangeEvent event listener that destroys and initializes the beans you need. For an example of this take a look at org.springframework.cloud.context.properties.ConfigurationPropertiesRebinder from spring-cloud-context module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文