Skip to content

Commit 9eed719

Browse files
committed
Do not register shutdownHook for WAR deployments
The application context shutdownHook is not needed for WAR deployments, and we should let the Servlet container handle the application lifecycle here. Closes gh-19398
1 parent 87de8a5 commit 9eed719

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -131,6 +131,7 @@ protected WebApplicationContext createRootApplicationContext(ServletContext serv
131131
if (this.registerErrorPageFilter) {
132132
application.addPrimarySources(Collections.singleton(ErrorPageFilterConfiguration.class));
133133
}
134+
application.setRegisterShutdownHook(false);
134135
return run(application);
135136
}
136137

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/support/SpringBootServletInitializerTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -100,6 +100,12 @@ void mainClassHasSensibleDefault() {
100100
WithConfigurationAnnotation.class);
101101
}
102102

103+
@Test
104+
void shutdownHookIsNotRegistered() {
105+
new WithConfigurationAnnotation().createRootApplicationContext(this.servletContext);
106+
assertThat(this.application).hasFieldOrPropertyWithValue("registerShutdownHook", false);
107+
}
108+
103109
@Test
104110
void errorPageFilterRegistrationCanBeDisabled() {
105111
WebServer webServer = new UndertowServletWebServerFactory(0).getWebServer((servletContext) -> {

0 commit comments

Comments
 (0)