【发布时间】:2019-01-26 01:10:01
【问题描述】:
@SpringBootApplication
public class ConfigClientApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
}
}
@Component
class ApplicationEventListener implements ApplicationListener<EnvironmentChangeEvent> {
@Override
public void onApplicationEvent(EnvironmentChangeEvent event) {
System.out.println("event listener");
}
}
@Component
class RefreshEventListener implements ApplicationListener<RefreshScopeRefreshedEvent> {
@Override
public void onApplicationEvent(final RefreshScopeRefreshedEvent event) {
System.out.println("refresh scope refresh event");
}
}
}
@Component
@ConfigurationProperties("person")
@RefreshScope
public class PersonConfiguration {
public String name;
//getter and setter for name
}
尝试测试是否在 RefreshScopeRefreshedEvent 监听器上调用了 onApplicationEvent。
更新了 git 中的配置,但未调用 RefreshScopeRefreshedEvent 侦听器。但是虽然调用了 EnvironmentChangeEvent 侦听器。
尝试调用/actuator/refresh,即使这里没有调用RefreshScopeRefreshedEvent监听器,但是调用了EnvironmentChangeEvent监听器。
这就是我在 git 中的配置方式
person:
name: first last
多次更新配置,每次只调用 EnvironmentChangeEvent。
我应该在此处更改什么以调用 RefreshScopeRefreshedEvent 侦听器。
【问题讨论】:
标签: spring spring-boot spring-cloud spring-cloud-config