In Spring Boot 2.1 and above it is as simple as adding this property to your .properties (or .yml) file:
server.http2.enabled=true
You can also do it programmatically like this (in one of your configuration classes):
@Bean
public ConfigurableServletWebServerFactory tomcatCustomizer() {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.addConnectorCustomizers(connector -> connector.addUpgradeProtocol(new Http2Protocol()));
return factory;
}