diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java index 9d3fb42c0a2..747055692d2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java @@ -24,7 +24,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; -import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.TestUtils; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; @@ -35,6 +34,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.properties.ServerProperties; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.context.ApplicationContextException; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -133,7 +133,7 @@ public class ServerPropertiesAutoConfigurationTests { this.context.register(Config.class, MutiServerPropertiesBeanConfig.class, ServerPropertiesAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); - this.thrown.expect(BeanCreationException.class); + this.thrown.expect(ApplicationContextException.class); this.thrown.expectMessage("Multiple ServerProperties"); this.context.refresh(); } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContext.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContext.java index 16026485001..d9139f237d3 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContext.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/EmbeddedWebApplicationContext.java @@ -131,7 +131,13 @@ public class EmbeddedWebApplicationContext extends GenericWebApplicationContext protected void onRefresh() { super.onRefresh(); registerShutdownHook(); - createEmbeddedServletContainer(); + try { + createEmbeddedServletContainer(); + } + catch (Throwable ex) { + throw new ApplicationContextException("Unable to start embedded container", + ex); + } } @Override diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java index d3303b39533..a2e1116cdc1 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainer.java @@ -17,6 +17,7 @@ package org.springframework.boot.context.embedded.tomcat; import org.apache.catalina.LifecycleException; +import org.apache.catalina.LifecycleState; import org.apache.catalina.connector.Connector; import org.apache.catalina.startup.Tomcat; import org.apache.commons.logging.Log; @@ -75,6 +76,10 @@ public class TomcatEmbeddedServletContainer implements EmbeddedServletContainer }; awaitThread.setDaemon(false); awaitThread.start(); + if (LifecycleState.FAILED.equals(this.tomcat.getConnector().getState())) { + this.tomcat.stop(); + throw new IllegalStateException("Tomcat connector in failed state"); + } } catch (Exception ex) { throw new EmbeddedServletContainerException(