@ -597,29 +597,12 @@ This support depends on the chosen web server and the application environment, s
[NOTE]
====
Spring Boot does not support `h2c`, the cleartext version of the HTTP/2 protocol.
So you must <<howto-configure-ssl, configure SSL first>>.
Spring Boot does not advise using `h2c`, the cleartext version of the HTTP/2 protocol.
As a result, the next sections require to <<howto-configure-ssl, configure SSL first>>.
If you still choose to use `h2c`, you can check <<howto-configure-http2-h2c, the dedicated section>>.
====
[[howto-configure-http2-undertow]]
==== HTTP/2 with Undertow
As of Undertow 1.4.0+, HTTP/2 is supported without any additional requirement on JDK8.
[[howto-configure-http2-jetty]]
==== HTTP/2 with Jetty
For HTTP/2 support, Jetty requires the additional `org.eclipse.jetty.http2:http2-server` dependency.
Now depending on your deployment, you also need to choose other dependencies:
* `org.eclipse.jetty:jetty-alpn-java-server` for applications running on JDK9+
* `org.eclipse.jetty:jetty-alpn-openjdk8-server` for applications running on JDK8u252+
* `org.eclipse.jetty:jetty-alpn-conscrypt-server` and the https://www.conscrypt.org/[Conscrypt library] with no JDK requirement
[[howto-configure-http2-tomcat]]
==== HTTP/2 with Tomcat
Spring Boot ships by default with Tomcat 9.0.x which supports HTTP/2 out of the box when using JDK 9 or later.
@ -639,6 +622,16 @@ Starting Tomcat 9.0.x on JDK 8 without that native support logs the following er
This error is not fatal, and the application still starts with HTTP/1.1 SSL support.
[[howto-configure-http2-jetty]]
==== HTTP/2 with Jetty
For HTTP/2 support, Jetty requires the additional `org.eclipse.jetty.http2:http2-server` dependency.
Now depending on your deployment, you also need to choose other dependencies:
* `org.eclipse.jetty:jetty-alpn-java-server` for applications running on JDK9+
* `org.eclipse.jetty:jetty-alpn-openjdk8-server` for applications running on JDK8u252+
* `org.eclipse.jetty:jetty-alpn-conscrypt-server` and the https://www.conscrypt.org/[Conscrypt library] with no JDK requirement
[[howto-configure-http2-netty]]
==== HTTP/2 with Reactor Netty
@ -652,6 +645,71 @@ Developers can choose to import only the required dependencies using a classifie
[[howto-configure-http2-undertow]]
==== HTTP/2 with Undertow
As of Undertow 1.4.0+, HTTP/2 is supported without any additional requirement on JDK8.
[[howto-configure-http2-h2c]]
==== h2c with supported servers
To enable `h2c`, you need to leave the configprop:server.http2.enabled[] property set to `false`,
and instead apply a customizer specific to your choice of server:
For Tomcat, we need to add an upgrade protocol:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@Bean
public TomcatConnectorCustomizer connectorCustomizer() {
return (connector) -> connector.addUpgradeProtocol(new Http2Protocol());
}
----
For Jetty, we need to add a connection factory to the existing connector:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@Bean
public JettyServerCustomizer serverCustomizer() {
return (server) -> {
HttpConfiguration configuration = new HttpConfiguration();
configuration.setSendServerVersion(false);
Arrays.stream(server.getConnectors())
.filter(connector -> connector instanceof ServerConnector)
.map(ServerConnector.class::cast)
.forEach(connector -> {
connector.addConnectionFactory(new HTTP2CServerConnectionFactory(configuration));
});
};
}
----
For Netty, we need to add `h2c` as a supported protocol:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@Bean
public NettyServerCustomizer serverCustomizer() {
return (server) -> server.protocol(HttpProtocol.H2C);
}
----
For Undertow, we need to enable the HTTP2 option:
[source,java,indent=0,subs="verbatim,quotes,attributes"]
----
@Bean
public UndertowBuilderCustomizer builderCustomizer() {
return (builder) -> {
builder.setServerOption(ENABLE_HTTP2, true);
};
}
----
[[howto-configure-webserver]]
=== Configure the Web Server
Generally, you should first consider using one of the many available configuration keys and customize your web server by adding new entries in your `application.properties` (or `application.yml`, or environment, etc. see "`<<howto-discover-build-in-options-for-external-properties>>`").