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
|
@Override
|
||||||
protected void onRefresh() {
|
protected void onRefresh() {
|
||||||
super.onRefresh();
|
super.onRefresh();
|
||||||
registerShutdownHook();
|
|
||||||
try {
|
try {
|
||||||
createEmbeddedServletContainer();
|
createEmbeddedServletContainer();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ import org.springframework.web.context.request.SessionScope;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
@ -109,14 +108,17 @@ public class EmbeddedWebApplicationContextTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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();
|
addEmbeddedServletContainerFactoryBean();
|
||||||
this.context.refresh();
|
this.context.refresh();
|
||||||
Field shutdownHookField = AbstractApplicationContext.class
|
Field shutdownHookField = AbstractApplicationContext.class
|
||||||
.getDeclaredField("shutdownHook");
|
.getDeclaredField("shutdownHook");
|
||||||
shutdownHookField.setAccessible(true);
|
shutdownHookField.setAccessible(true);
|
||||||
Object shutdownHook = shutdownHookField.get(this.context);
|
Object shutdownHook = shutdownHookField.get(this.context);
|
||||||
assertThat(shutdownHook, not(nullValue()));
|
assertThat(shutdownHook, nullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue