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?
question from:https://stackoverflow.com/questions/38612704/enable-http2-with-tomcat-in-spring-bootTomcat 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?
question from:https://stackoverflow.com/questions/38612704/enable-http2-with-tomcat-in-spring-bootYou need to add the HTTP 2 upgrade protocol to Tomcat's connector. You can do that by customizing the embedded Tomcat container:
@Bean
public EmbeddedServletContainerCustomizer tomcatCustomizer() {
return (container) -> {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
((TomcatEmbeddedServletContainerFactory) container)
.addConnectorCustomizers((connector) -> {
connector.addUpgradeProtocol(new Http2Protocol());
});
}
};
}
@Bean
public EmbeddedServletContainerCustomizer tomcatCustomizer() {
return new EmbeddedServletContainerCustomizer() {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
if (container instanceof TomcatEmbeddedServletContainerFactory) {
((TomcatEmbeddedServletContainerFactory) container)
.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
connector.addUpgradeProtocol(new Http2Protocol());
}
});
}
}
};
}