diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 8f91d17d3f..57261f609f 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -111,7 +111,7 @@ 2.9.0 2.25.1 2.0.4 - 9.4.12.v20180830 + 9.4.14.v20181114 2.2.0.v201112011158 8.0.33 1.1-rev-1 diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java index 71a6d0edc9..32bf231993 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java @@ -16,6 +16,7 @@ package org.springframework.boot.context.embedded.jetty; +import java.io.IOException; import java.net.BindException; import java.util.List; @@ -142,8 +143,9 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer { try { connector.start(); } - catch (BindException ex) { - if (connector instanceof NetworkConnector) { + catch (IOException ex) { + if (connector instanceof NetworkConnector + && findBindException(ex) != null) { throw new PortInUseException( ((NetworkConnector) connector).getPort()); } @@ -166,6 +168,16 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer { } } + private BindException findBindException(Throwable ex) { + if (ex == null) { + return null; + } + if (ex instanceof BindException) { + return (BindException) ex; + } + return findBindException(ex.getCause()); + } + private String getActualPortsDescription() { StringBuilder ports = new StringBuilder(); for (Connector connector : this.server.getConnectors()) { diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/ServletContextInitializerConfiguration.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/ServletContextInitializerConfiguration.java index 4e61ed5fde..b0add66022 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/ServletContextInitializerConfiguration.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/ServletContextInitializerConfiguration.java @@ -18,7 +18,6 @@ package org.springframework.boot.context.embedded.jetty; import javax.servlet.ServletException; -import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.WebAppContext; @@ -49,54 +48,35 @@ public class ServletContextInitializerConfiguration extends AbstractConfiguratio @Override public void configure(WebAppContext context) throws Exception { - context.addBean(new Initializer(context), true); - } - - /** - * Jetty {@link AbstractLifeCycle} to call the {@link ServletContextInitializer - * ServletContextInitializers}. - */ - private class Initializer extends AbstractLifeCycle { - - private final WebAppContext context; - - Initializer(WebAppContext context) { - this.context = context; + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(context.getClassLoader()); + try { + callInitializers(context); } - - @Override - protected void doStart() throws Exception { - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(this.context.getClassLoader()); - try { - callInitializers(); - } - finally { - Thread.currentThread().setContextClassLoader(classLoader); - } + finally { + Thread.currentThread().setContextClassLoader(classLoader); } + } - private void callInitializers() throws ServletException { - try { - setExtendedListenerTypes(true); - for (ServletContextInitializer initializer : ServletContextInitializerConfiguration.this.initializers) { - initializer.onStartup(this.context.getServletContext()); - } - } - finally { - setExtendedListenerTypes(false); + private void callInitializers(WebAppContext context) throws ServletException { + try { + setExtendedListenerTypes(context, true); + for (ServletContextInitializer initializer : this.initializers) { + initializer.onStartup(context.getServletContext()); } } - - private void setExtendedListenerTypes(boolean extended) { - try { - this.context.getServletContext().setExtendedListenerTypes(extended); - } - catch (NoSuchMethodError ex) { - // Not available on Jetty 8 - } + finally { + setExtendedListenerTypes(context, false); } + } + private void setExtendedListenerTypes(WebAppContext context, boolean extended) { + try { + context.getServletContext().setExtendedListenerTypes(extended); + } + catch (NoSuchMethodError ex) { + // Not available on Jetty 8 + } } }