Skip to content
Advertisement

Enable HTTP2 with Tomcat in Spring Boot

Tomcat 8.5, which will be the default in Spring Boot 1.4, supports HTTP/2.

How can HTTP/2 be enabled in a Spring Boot application?

Advertisement

Answer

The most elegant and best-performing way to enable HTTP/2 with a Spring Boot application follows here.

First, as mentioned in Andy Wilkinson’s answer, you need to enable HTTP/2 at Tomcat level:

JavaScript

In case you are not using an embedded Tomcat, you can set up HTTP/2 listening like this:

JavaScript

Remember that you need Tomcat >= 8.5.

Then, you should use HAProxy (version >= 1.7) in front of Tomcat to take care of encryption.

The client will speak https to HAProxy, and HAProxy will speak cleartext HTTP/1.1 or HTTP/2 to the backend, as the client requested. There will be no unnecessary protocol translations.

The matching HAProxy-configuration is here:

JavaScript

Edit 2019

I face two problems when using mode “tcp”

  • Compression does not work, since it depends on mode http. So the backend has to take care of it
  • The backend can not see the client’s IP-address. Probably I need NAT. Still investigating…

Generally, since haproxy proxies a lower level tcp connection, there is no access to any http stuff

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement