Configure HTTP/2

You can enable HTTP/2 support in your Spring Boot application with the server.http2.enabled configuration property. Both h2 (HTTP/2 over TLS) and h2c (HTTP/2 over TCP) are supported. To use h2, SSL must also be enabled. When SSL is not enabled, h2c will be used. You may, for example, want to use h2c when your application is running behind a proxy server that is performing TLS termination.

HTTP/2 With Tomcat

Spring Boot ships by default with Tomcat 10.1.x which supports h2c and h2 out of the box. Alternatively, you can use libtcnative for h2 support if the library and its dependencies are installed on the host operating system.

The library directory 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 official Tomcat documentation.

HTTP/2 With Jetty

For HTTP/2 support, Jetty requires the additional org.eclipse.jetty.http2:http2-server dependency. To use h2c no other dependencies are required. To use h2, you also need to choose one of the following dependencies, depending on your deployment:

  • org.eclipse.jetty:jetty-alpn-java-server to use the JDK built-in support

  • org.eclipse.jetty:jetty-alpn-conscrypt-server and the Conscrypt library

HTTP/2 With Reactor Netty

The spring-boot-webflux-starter is using by default Reactor Netty as a server. Reactor Netty supports h2c and h2 out of the box. For optimal runtime performance, this server also supports h2 with native libraries. To enable that, your application needs to have an additional dependency.

Spring Boot manages the version for the io.netty:netty-tcnative-boringssl-static "uber jar", containing native libraries for all platforms. Developers can choose to import only the required dependencies using a classifier (see the Netty official documentation).

HTTP/2 With Undertow

Undertow supports h2c and h2 out of the box.