mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Ensure registerShutdownHook is called for apps
This commit is contained in:
parent
5995b7727a
commit
b65625bec3
@ -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);
|
||||
|
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user