@Test
public void contextRefreshedEventListener() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebEnvironment(false);
final AtomicReference<ApplicationContext> reference = new AtomicReference<ApplicationContext>();
class InitializerListener implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
reference.set(event.getApplicationContext());
}
}
application.setListeners(Arrays.asList(new InitializerListener()));
this.context = application.run("--foo=bar");
assertThat(this.context).isSameAs(reference.get());
// Custom initializers do not switch off the defaults
assertThat(getEnvironment().getProperty("foo")).isEqualTo("bar");
}
SpringApplicationTests.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:spring-boot-concourse
作者:
评论列表
文章目录