Don't register shutdown hook from embedded context
Change `EmbeddedWebApplicationContext` to no longer automatically call `registerShutdownHook()`. Shutdown hooks must now be registered by the caller (for users of SpringApplication this will happen automatically). Fixes gh-314
This commit is contained in:
parent
5863795e10
commit
b21f56a292
|
|
@ -128,7 +128,6 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
|
|||
@Override
|
||||
protected void onRefresh() {
|
||||
super.onRefresh();
|
||||
registerShutdownHook();
|
||||
try {
|
||||
createEmbeddedServletContainer();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ import org.springframework.web.context.request.SessionScope;
|
|||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
|
@ -109,14 +108,17 @@ public class EmbeddedWebApplicationContextTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void registersShutdownHook() throws Exception {
|
||||
public void doesNotRegistersShutdownHook() throws Exception {
|
||||
// See gh-314 for background. We no longer register the shutdown hook
|
||||
// since it is really the callers responsibility. The shutdown hook could
|
||||
// also be problematic in a classic WAR deployment.
|
||||
addEmbeddedServletContainerFactoryBean();
|
||||
this.context.refresh();
|
||||
Field shutdownHookField = AbstractApplicationContext.class
|
||||
.getDeclaredField("shutdownHook");
|
||||
shutdownHookField.setAccessible(true);
|
||||
Object shutdownHook = shutdownHookField.get(this.context);
|
||||
assertThat(shutdownHook, not(nullValue()));
|
||||
assertThat(shutdownHook, nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue