mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Make Jetty Server fail when its WebAppContext fails to start
Closes gh-13803
This commit is contained in:
parent
912eb53d7a
commit
56cb968b62
@ -104,7 +104,7 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer {
|
||||
this.server.start();
|
||||
this.server.setStopAtShutdown(false);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
// Ensure process isn't left running
|
||||
stopSilently();
|
||||
throw new EmbeddedServletContainerException(
|
||||
|
@ -368,6 +368,7 @@ public class JettyEmbeddedServletContainerFactory
|
||||
Configuration[] configurations = getWebAppContextConfigurations(context,
|
||||
initializersToUse);
|
||||
context.setConfigurations(configurations);
|
||||
context.setThrowUnavailableOnStartupException(true);
|
||||
configureSession(context);
|
||||
postProcessWebAppContext(context);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -28,6 +29,8 @@ import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
@ -369,6 +372,42 @@ public class JettyEmbeddedServletContainerFactoryTests
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void faultyListenerCausesStartFailure() throws Exception {
|
||||
JettyEmbeddedServletContainerFactory factory = getFactory();
|
||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Server server) {
|
||||
Collection<WebAppContext> contexts = server.getBeans(WebAppContext.class);
|
||||
contexts.iterator().next().addEventListener(new ServletContextListener() {
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
this.thrown.expect(EmbeddedServletContainerException.class);
|
||||
JettyEmbeddedServletContainer jettyContainer = (JettyEmbeddedServletContainer) factory
|
||||
.getEmbeddedServletContainer();
|
||||
try {
|
||||
jettyContainer.start();
|
||||
}
|
||||
finally {
|
||||
QueuedThreadPool threadPool = (QueuedThreadPool) jettyContainer.getServer()
|
||||
.getThreadPool();
|
||||
assertThat(threadPool.isRunning()).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startFailsWhenThreadPoolIsTooSmall() throws Exception {
|
||||
JettyEmbeddedServletContainerFactory factory = getFactory();
|
||||
|
Loading…
Reference in New Issue
Block a user