Spring Cloud RefreshScope 刷新后挂钩

dmf*_*rey 4 spring spring-boot spring-cloud spring-cloud-config

是否有 @RequestScope 刷新后挂钩的概念?

用例:我们需要推送配置更改。目前,这是手动的,并作为应用程序重新启动的一部分触发。但是,如果我们可以触发 /bus/refresh,一旦环境刷新,就不会销毁 bean(在本例中为 @Service),而是在新环境值更新后触发一些配置更改?这样的事情可能吗?

dmf*_*rey 5

我使用的解决方案是让我的 @Service 实现 ApplicationListener 并覆盖 onApplicationEvent(RefreshRemoteApplicationEvent event)。这已经在 RefreshListener 中执行,但我的实现能够检查更改的键并根据客户端为特定键更改设置的规则做出反应。