Merge branch '1.2.x'
This commit is contained in:
@@ -146,9 +146,9 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() {
|
||||
protected void onClose() {
|
||||
super.onClose();
|
||||
stopAndReleaseEmbeddedServletContainer();
|
||||
super.doClose();
|
||||
}
|
||||
|
||||
private synchronized void createEmbeddedServletContainer() {
|
||||
|
||||
@@ -43,14 +43,11 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
import org.springframework.beans.factory.config.Scope;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory.MockEmbeddedServletContainer;
|
||||
import org.springframework.boot.context.web.ServerPortInfoApplicationContextInitializer;
|
||||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -68,7 +65,6 @@ import org.springframework.web.filter.GenericFilterBean;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -485,21 +481,6 @@ public class EmbeddedWebApplicationContextTests {
|
||||
sameInstance(scope));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void containerIsStoppedBeforeContextIsClosed() {
|
||||
addEmbeddedServletContainerFactoryBean();
|
||||
this.context.registerBeanDefinition("shutdownOrderingValidator",
|
||||
BeanDefinitionBuilder.rootBeanDefinition(ShutdownOrderingValidator.class)
|
||||
.addConstructorArgReference("embeddedServletContainerFactory")
|
||||
.getBeanDefinition());
|
||||
this.context.refresh();
|
||||
ShutdownOrderingValidator validator = this.context
|
||||
.getBean(ShutdownOrderingValidator.class);
|
||||
this.context.close();
|
||||
assertThat(validator.destroyed, is(true));
|
||||
assertThat(validator.containerStoppedFirst, is(true));
|
||||
}
|
||||
|
||||
private void addEmbeddedServletContainerFactoryBean() {
|
||||
this.context.registerBeanDefinition("embeddedServletContainerFactory",
|
||||
new RootBeanDefinition(MockEmbeddedServletContainerFactory.class));
|
||||
@@ -552,25 +533,4 @@ public class EmbeddedWebApplicationContextTests {
|
||||
|
||||
}
|
||||
|
||||
protected static class ShutdownOrderingValidator implements DisposableBean {
|
||||
|
||||
private final MockEmbeddedServletContainer servletContainer;
|
||||
|
||||
private boolean destroyed = false;
|
||||
|
||||
private boolean containerStoppedFirst = false;
|
||||
|
||||
ShutdownOrderingValidator(
|
||||
MockEmbeddedServletContainerFactory servletContainerFactory) {
|
||||
this.servletContainer = servletContainerFactory.getContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
this.destroyed = true;
|
||||
this.containerStoppedFirst = this.servletContainer.isStopped();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -90,8 +90,6 @@ public class MockEmbeddedServletContainerFactory
|
||||
|
||||
private final int port;
|
||||
|
||||
private boolean stopped = false;
|
||||
|
||||
public MockEmbeddedServletContainer(ServletContextInitializer[] initializers,
|
||||
int port) {
|
||||
this.initializers = initializers;
|
||||
@@ -176,11 +174,6 @@ public class MockEmbeddedServletContainerFactory
|
||||
public void stop() {
|
||||
this.servletContext = null;
|
||||
this.registeredServlets.clear();
|
||||
this.stopped = true;
|
||||
}
|
||||
|
||||
public boolean isStopped() {
|
||||
return this.stopped;
|
||||
}
|
||||
|
||||
public Servlet[] getServlets() {
|
||||
|
||||
Reference in New Issue
Block a user