From 45fdf2ffa4b4fd9e30300975d2015357e243892e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 29 May 2018 16:52:44 +0100 Subject: [PATCH] Support Tomcat 9 and Undertow 2 Closes gh-11749 Closes gh-12243 --- .../spring-boot-dependencies/pom.xml | 6 +++--- .../src/main/asciidoc/getting-started.adoc | 8 ++++---- .../src/main/asciidoc/howto.adoc | 20 ++++++++++--------- .../main/asciidoc/spring-boot-features.adoc | 6 +++--- .../spring-boot-starter-jetty/pom.xml | 1 + .../spring-boot-starter-undertow/pom.xml | 2 +- .../springframework/boot/maven/Verify.java | 6 +++--- .../TomcatServletWebServerFactoryTests.java | 4 +--- .../spring-boot-sample-jetty-jsp/pom.xml | 1 + .../spring-boot-sample-jetty-ssl/pom.xml | 1 + .../spring-boot-sample-jetty/pom.xml | 1 + 11 files changed, 30 insertions(+), 26 deletions(-) diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index 2d5a4f8a83..6bda2aa9d5 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -147,7 +147,7 @@ 3.9.1 2.29.3 4.1.2 - 3.1.0 + 4.0.1 1.7.25 1.19 7.2.1 @@ -175,9 +175,9 @@ 2.3.0 2.0.1 3.0.1.RELEASE - 8.5.31 + 9.0.10 4.0.6 - 1.4.25.Final + 2.0.9.Final 3325375 0.35 1.6.3 diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc index 62bffbcab9..6f5b5e0f00 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/getting-started.adoc @@ -51,14 +51,14 @@ Spring Boot supports the following embedded servlet containers: |=== |Name |Servlet Version -|Tomcat 8.5 -|3.1 +|Tomcat 9.0 +|4.0 |Jetty 9.4 |3.1 -|Undertow 1.4 -|3.1 +|Undertow 2.0 +|4.0 |=== You can also deploy Spring Boot applications to any Servlet 3.1+ compatible container. diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc index 0d83beb636..4c05747823 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -523,6 +523,9 @@ The following Maven example shows how to exclude Tomcat and include Jetty for Sp [source,xml,indent=0,subs="verbatim,quotes,attributes"] ---- + + 3.1.0 + org.springframework.boot spring-boot-starter-web @@ -541,6 +544,9 @@ The following Maven example shows how to exclude Tomcat and include Jetty for Sp ---- +NOTE: The version of the Servlet API has been overridden as, unlike Tomcat 9 and Undertow +2.0, Jetty 9.4 does not support Servlet 4.0. + The following Gradle example shows how to exclude Netty and include Undertow for Spring WebFlux: @@ -727,16 +733,16 @@ To enable that support, your application needs to have two additional dependenci [[howto-configure-http2-tomcat]] ==== HTTP/2 with Tomcat -Spring Boot ships by default with Tomcat 8.5.x. With that version, HTTP/2 is only -supported if the `libtcnative` library and its dependencies are installed on the host -operating system. +Spring Boot ships by default with Tomcat 9.0.x which supports HTTP/2 out of the box when +using JDK 9 or later. Alternatively, HTTP/2 can be used on JDK 8 if the `libtcnative` +library and its dependencies are installed on the host operating system. The library folder must be made available, if not already, to the JVM library path. You can do so with a JVM argument such as `-Djava.library.path=/usr/local/opt/tomcat-native/lib`. More on this in the -https://tomcat.apache.org/tomcat-8.5-doc/apr.html[official Tomcat documentation]. +https://tomcat.apache.org/tomcat-9.0-doc/apr.html[official Tomcat documentation]. -Starting Tomcat 8.5.x without that native support logs the following error: +Starting Tomcat 9.0.x on JDK 8 without that native support logs the following error: [indent=0,subs="attributes"] ---- @@ -745,10 +751,6 @@ Starting Tomcat 8.5.x without that native support logs the following error: This error is not fatal, and the application still starts with HTTP/1.1 SSL support. -Running your application with Tomcat 9.0.x and JDK9 does not require any native library to -be installed. To use Tomcat 9, you can override the `tomcat.version` build property with -the version of your choice. - [[howto-configure-webserver]] diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index b1262bf304..638354c1a8 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -7409,9 +7409,9 @@ include::{test-examples}/web/client/SampleWebClientTests.java[tag=test] [[boot-features-websockets]] == WebSockets -Spring Boot provides WebSockets auto-configuration for embedded Tomcat 8.5, Jetty -9, and Undertow. If you deploy a war file to a standalone container, Spring Boot assumes -that the container is responsible for the configuration of its WebSocket support. +Spring Boot provides WebSockets auto-configuration for embedded Tomcat, Jetty, and +Undertow. If you deploy a war file to a standalone container, Spring Boot assumes that the +container is responsible for the configuration of its WebSocket support. Spring Framework provides {spring-reference}web.html#websocket[rich WebSocket support] that can be easily accessed through the `spring-boot-starter-websocket` module. diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-jetty/pom.xml b/spring-boot-project/spring-boot-starters/spring-boot-starter-jetty/pom.xml index 537da2c678..0d8fc32869 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-jetty/pom.xml +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-jetty/pom.xml @@ -13,6 +13,7 @@ alternative to spring-boot-starter-tomcat ${basedir}/../../.. + 3.1.0 diff --git a/spring-boot-project/spring-boot-starters/spring-boot-starter-undertow/pom.xml b/spring-boot-project/spring-boot-starters/spring-boot-starter-undertow/pom.xml index c29c6bbc2c..7c1162b5cf 100644 --- a/spring-boot-project/spring-boot-starters/spring-boot-starter-undertow/pom.xml +++ b/spring-boot-project/spring-boot-starters/spring-boot-starter-undertow/pom.xml @@ -25,7 +25,7 @@ org.jboss.spec.javax.servlet - jboss-servlet-api_3.1_spec + jboss-servlet-api_4.0_spec diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java index 982feecff6..3121e1bf7d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/Verify.java @@ -230,7 +230,7 @@ public final class Verify { super.verifyZipEntries(verifier); verifier.assertHasEntryNameStartingWith("BOOT-INF/lib/spring-context"); verifier.assertHasEntryNameStartingWith("BOOT-INF/lib/spring-core"); - verifier.assertHasEntryNameStartingWith("BOOT-INF/lib/javax.servlet-api-3"); + verifier.assertHasEntryNameStartingWith("BOOT-INF/lib/javax.servlet-api-4"); assertThat(verifier .hasEntry("org/springframework/boot/loader/JarLauncher.class")) .as("Unpacked launcher classes").isTrue(); @@ -263,7 +263,7 @@ public final class Verify { verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-context"); verifier.assertHasEntryNameStartingWith("WEB-INF/lib/spring-core"); verifier.assertHasEntryNameStartingWith( - "WEB-INF/lib-provided/javax.servlet-api-3"); + "WEB-INF/lib-provided/javax.servlet-api-4"); assertThat(verifier .hasEntry("org/" + "springframework/boot/loader/JarLauncher.class")) .as("Unpacked launcher classes").isTrue(); @@ -314,7 +314,7 @@ public final class Verify { super.verifyZipEntries(verifier); verifier.assertHasEntryNameStartingWith("lib/spring-context"); verifier.assertHasEntryNameStartingWith("lib/spring-core"); - verifier.assertHasNoEntryNameStartingWith("lib/javax.servlet-api-3"); + verifier.assertHasNoEntryNameStartingWith("lib/javax.servlet-api"); assertThat(verifier .hasEntry("org/" + "springframework/boot/loader/JarLauncher.class")) .as("Unpacked launcher classes").isFalse(); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java index 6ab1dfd773..c2b894d2d9 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/tomcat/TomcatServletWebServerFactoryTests.java @@ -63,7 +63,6 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -181,8 +180,7 @@ public class TomcatServletWebServerFactoryTests TomcatServletWebServerFactory factory = getFactory(); Connector[] listeners = new Connector[4]; for (int i = 0; i < listeners.length; i++) { - Connector connector = mock(Connector.class); - given(connector.getState()).willReturn(LifecycleState.STOPPED); + Connector connector = new Connector(); listeners[i] = connector; } factory.addAdditionalTomcatConnectors(listeners); diff --git a/spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml b/spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml index e208d3a886..a2ddaa620d 100644 --- a/spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml +++ b/spring-boot-samples/spring-boot-sample-jetty-jsp/pom.xml @@ -15,6 +15,7 @@ ${basedir}/../.. / + 3.1.0 diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml b/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml index 05468a45b3..1694152789 100644 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/pom.xml @@ -13,6 +13,7 @@ Spring Boot Jetty SSL Sample ${basedir}/../.. + 3.1.0 diff --git a/spring-boot-samples/spring-boot-sample-jetty/pom.xml b/spring-boot-samples/spring-boot-sample-jetty/pom.xml index b5729f797a..395594a747 100644 --- a/spring-boot-samples/spring-boot-sample-jetty/pom.xml +++ b/spring-boot-samples/spring-boot-sample-jetty/pom.xml @@ -13,6 +13,7 @@ Spring Boot Jetty Sample ${basedir}/../.. + 3.1.0