【发布时间】:2018-10-12 14:33:45
【问题描述】:
我想在应用程序启动后以及 Spring Cloud 配置存储库/服务器中的属性更改时立即执行自定义逻辑。所以我写了这样的东西:
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
@Configuration
public class AppConfiguration implements ApplicationListener<EnvironmentChangeEvent> {
@Override
public void onApplicationEvent(EnvironmentChangeEvent event) {
// Custom logic goes here. It should be executed on both app context load time
// and on any property change time
}
}
上面的代码在几个月前的应用程序加载时间和属性更改时工作。但是这段代码最近停止工作了,我猜是 Spring boot / 云版本更新。
目前我正在使用 Sprig boot 1.5.10 和 Cloud Edgware.SR3
【问题讨论】:
-
看起来像 EnvironmentChangedEvent 以前在启动时调用,但现在在较新的版本中它不会在启动时调用。
标签: spring-boot spring-cloud spring-cloud-config