刷新外部罐子
当有配置更改时,我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@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 atorg.springframework.cloud.context.properties.ConfigurationPropertiesRebinder
fromspring-cloud-context
module.