Tomcat 8.5
, which will be the default in Spring Boot 1.4
, (to be released tomorrow) supports http2
.
How can http2
be enabled in a Spring Boot
application?
Tomcat 8.5
, which will be the default in Spring Boot 1.4
, (to be released tomorrow) supports http2
.
How can http2
be enabled in a Spring Boot
application?
You need to add the HTTP 2 upgrade protocol to Tomcat's connector. You can do that by customizing the embedded Tomcat container:
Java 8:
Java 7:
In Spring Boot 2.1 and above it is as simple as adding this property to your .properties (or .yml) file:
You can also do it programmatically like this (in one of your configuration classes):
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:
In case you are not using an embedded Tomcat, you can set up HTTP/2 listening like this:
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:
Edit 2019
I face two problems when using mode "tcp"
Generally, since haproxy proxies a lower level tcp connection, there is no access to any http stuff
In Spring Boot 2 you first need a certificate - it can by generated like this:
Than you just need to add this certificate to classpath and add needed properties to application.properties: