Ensure registerShutdownHook is called for apps

This commit is contained in:
Phillip Webb 2013-07-31 01:54:53 -07:00
parent 5995b7727a
commit b65625bec3
2 changed files with 10 additions and 0 deletions

View File

@ -254,6 +254,7 @@ public class SpringApplication {
// Create, load, refresh and run the ApplicationContext
ApplicationContext context = createApplicationContext();
if (context instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) context).registerShutdownHook();
((ConfigurableApplicationContext) context).setEnvironment(environment);
}
postProcessApplicationContext(context);

View File

@ -326,6 +326,15 @@ public class SpringApplicationTests {
assertThat(application.getShowBanner(), is(false));
}
@Test
public void registerShutdownHook() throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
ConfigurableApplicationContext applicationContext = spy(new AnnotationConfigApplicationContext());
application.setApplicationContext(applicationContext);
application.run();
verify(applicationContext).registerShutdownHook();
}
private boolean hasPropertySource(ConfigurableEnvironment environment,
Class<?> propertySourceClass, String name) {
for (PropertySource<?> source : environment.getPropertySources()) {