Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable HTTP 2.0 for Undertow in Spring Boot

I wonder how I can enable the HTTP 2.0 for Undertow using Spring Boot, I monitored the protocol and currently HTTPS is using 1.1.

Is there any property for it? Or should I create a EmbeddedServletContainerFactory with this option.

Tks,

like image 362
Carlos Alberto Avatar asked Nov 20 '15 19:11

Carlos Alberto


People also ask

How do I enable http2 support in spring boot?

You can enable HTTP/2 support in your Spring Boot application with the server. http2. enabled configuration property. This support depends on the chosen web server and the application environment, since that protocol is not supported out-of-the-box by JDK8.

What is Springboot undertow?

Spring Boot Undertow Spring is a popular Java application framework and Spring Boot is an evolution of Spring that helps create stand-alone, production-grade Spring based applications easily.

How do I use a Jetty server in spring boot?

To use Jetty in your Spring Boot application, we can use the spring-boot-starter-jetty starter. Spring Boot provides Tomcat and Jetty dependencies bundled together as separate starters to help make this process as easy as possible. Add the spring-boot-starter-jetty starter in your pom. xml file.


1 Answers

You need to add the following bean to the configuration

    @Bean
    UndertowEmbeddedServletContainerFactory embeddedServletContainerFactory() {
        UndertowEmbeddedServletContainerFactory factory = new UndertowEmbeddedServletContainerFactory();
        factory.addBuilderCustomizers(
                builder -> builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true));
        return factory;
    }

Then start the application with alpn-boot-8.1.9.v20160720.jar in the boot class path

java -Xbootclasspath/p:<<location>>/alpn-boot-8.1.9.v20160720.jar -jar <<your application>>
like image 65
jozzy Avatar answered Oct 22 '22 04:10

jozzy