Enable HTTP2 with Tomcat in Spring Boot
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Enabling HTTP/2 in Spring Boot with embedded Tomcat is mostly about getting the transport stack right. The usual failure mode is enabling server.http2.enabled=true and then assuming the protocol will negotiate automatically even though SSL, ALPN support, or a reverse proxy still blocks the path.
The Core Requirements
For the usual browser-facing setup, HTTP/2 over Tomcat typically needs:
- Spring Boot version that supports HTTP/2 configuration
- embedded Tomcat with HTTP/2 support
- TLS enabled on the connector
- a Java runtime with ALPN support
In practice, modern JDKs make this easier than older Java versions. If you are on a current JDK and recent Spring Boot line, the configuration is much simpler than it used to be.
Turn On HTTP/2 in Spring Boot
The Spring Boot flag is straightforward:
This tells Boot to start Tomcat with SSL enabled and HTTP/2 support requested.
The TLS part matters. In most real deployments, HTTP/2 over browsers is negotiated over TLS. If you skip TLS, many clients will never use HTTP/2 even if the server side is otherwise capable.
A Minimal Spring Boot Application
A small controller is enough to test the protocol once the server is configured.
With the SSL and HTTP/2 properties in place, this is enough for a local verification run.
Test the Negotiated Protocol
Do not assume HTTP/2 is active just because the app starts. Check the negotiated protocol explicitly.
Using curl:
The response should show an HTTP/2 protocol line when negotiation succeeds.
You can also inspect the browser developer tools network panel. That often shows the protocol used for the request.
Understand the Tomcat Side
If Spring Boot is using embedded Tomcat, Boot handles most of the connector wiring. Even so, the lower-level rule still matters: Tomcat can only negotiate HTTP/2 when the runtime and connector settings support it end to end.
If HTTP/2 does not activate, check these layers:
- SSL is really enabled
- the JDK supports ALPN for your runtime path
- the embedded Tomcat version supports HTTP/2
- a reverse proxy in front is not terminating TLS and downgrading the backend protocol
That last point matters in real deployments. If Nginx, Apache, or a cloud load balancer sits in front of the app, the browser may speak HTTP/2 to the edge while the proxy forwards HTTP/1.1 to Tomcat. That is not inherently wrong, but it means Tomcat-level HTTP/2 might not change the user-facing protocol at all.
Local SSL Material for Testing
For local development, a self-signed certificate is enough to prove the protocol path.
Place the generated keystore where Spring Boot can load it, then start the application and test with curl -k.
Common Pitfalls
- Enabling
server.http2.enabled=truewithout configuring SSL. - Assuming HTTP/2 is active without verifying the negotiated protocol.
- Forgetting that a reverse proxy may terminate HTTP/2 before traffic reaches Tomcat.
- Using an older runtime or stack combination that lacks proper ALPN support.
- Debugging controller code when the real issue is connector or TLS configuration.
Summary
- HTTP/2 on Spring Boot with Tomcat depends on connector and TLS configuration, not controller code.
- In most browser-facing setups, the Boot flag and SSL both need to be configured.
- Verify negotiation with
curl --http2or browser tools instead of assuming it worked. - Check whether a reverse proxy terminates or downgrades the protocol before traffic reaches Tomcat.
- Treat HTTP/2 enablement as an end-to-end transport concern rather than a single property toggle.
Related reading
- Enable role authentication with spring boot security and keycloak?
- EnableGlobalMethodSecurity is deprecated in the new spring boot 3.0
- EnableGlobalMethodSecurity vs EnableWebSecurity
- EnableTransactionManagement in Spring Boot
- Encoding as Base64 in Java
- End to end integration test for multiple spring boot applications under Maven
- Environment Specific application.properties file in Spring Boot application
- Environment variables for list in spring boot configuration

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.