Skip to content

Commit b37eecc

Browse files
committed
Merge branch '2.2.x' into 2.3.x
Closes gh-23812
2 parents 43cfeba + 9478cd2 commit b37eecc

File tree

3 files changed

+85
-20
lines changed

3 files changed

+85
-20
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto.adoc

+78-20
Original file line numberDiff line numberDiff line change
@@ -582,29 +582,12 @@ This support depends on the chosen web server and the application environment, s
582582

583583
[NOTE]
584584
====
585-
Spring Boot does not support `h2c`, the cleartext version of the HTTP/2 protocol.
586-
So you must <<howto-configure-ssl, configure SSL first>>.
585+
Spring Boot does not advise using `h2c`, the cleartext version of the HTTP/2 protocol.
586+
As a result, the next sections require to <<howto-configure-ssl, configure SSL first>>.
587+
If you still choose to use `h2c`, you can check <<howto-configure-http2-h2c, the dedicated section>>.
587588
====
588589

589590

590-
591-
[[howto-configure-http2-undertow]]
592-
==== HTTP/2 with Undertow
593-
As of Undertow 1.4.0+, HTTP/2 is supported without any additional requirement on JDK8.
594-
595-
596-
597-
[[howto-configure-http2-jetty]]
598-
==== HTTP/2 with Jetty
599-
For HTTP/2 support, Jetty requires the additional `org.eclipse.jetty.http2:http2-server` dependency.
600-
Now depending on your deployment, you also need to choose other dependencies:
601-
602-
* `org.eclipse.jetty:jetty-alpn-java-server` for applications running on JDK9+
603-
* `org.eclipse.jetty:jetty-alpn-openjdk8-server` for applications running on JDK8u252+
604-
* `org.eclipse.jetty:jetty-alpn-conscrypt-server` and the https://www.conscrypt.org/[Conscrypt library] with no JDK requirement
605-
606-
607-
608591
[[howto-configure-http2-tomcat]]
609592
==== HTTP/2 with Tomcat
610593
Spring Boot ships by default with Tomcat 9.0.x which supports HTTP/2 out of the box when using JDK 9 or later.
@@ -624,6 +607,16 @@ Starting Tomcat 9.0.x on JDK 8 without that native support logs the following er
624607
This error is not fatal, and the application still starts with HTTP/1.1 SSL support.
625608

626609

610+
[[howto-configure-http2-jetty]]
611+
==== HTTP/2 with Jetty
612+
For HTTP/2 support, Jetty requires the additional `org.eclipse.jetty.http2:http2-server` dependency.
613+
Now depending on your deployment, you also need to choose other dependencies:
614+
615+
* `org.eclipse.jetty:jetty-alpn-java-server` for applications running on JDK9+
616+
* `org.eclipse.jetty:jetty-alpn-openjdk8-server` for applications running on JDK8u252+
617+
* `org.eclipse.jetty:jetty-alpn-conscrypt-server` and the https://www.conscrypt.org/[Conscrypt library] with no JDK requirement
618+
619+
627620

628621
[[howto-configure-http2-netty]]
629622
==== HTTP/2 with Reactor Netty
@@ -637,6 +630,71 @@ Developers can choose to import only the required dependencies using a classifie
637630

638631

639632

633+
[[howto-configure-http2-undertow]]
634+
==== HTTP/2 with Undertow
635+
As of Undertow 1.4.0+, HTTP/2 is supported without any additional requirement on JDK8.
636+
637+
638+
639+
[[howto-configure-http2-h2c]]
640+
==== h2c with supported servers
641+
To enable `h2c`, you need to leave the configprop:server.http2.enabled[] property set to `false`,
642+
and instead apply a customizer specific to your choice of server:
643+
644+
For Tomcat, we need to add an upgrade protocol:
645+
646+
[source,java,indent=0,subs="verbatim,quotes,attributes"]
647+
----
648+
@Bean
649+
public TomcatConnectorCustomizer connectorCustomizer() {
650+
return (connector) -> connector.addUpgradeProtocol(new Http2Protocol());
651+
}
652+
----
653+
654+
For Jetty, we need to add a connection factory to the existing connector:
655+
656+
[source,java,indent=0,subs="verbatim,quotes,attributes"]
657+
----
658+
@Bean
659+
public JettyServerCustomizer serverCustomizer() {
660+
return (server) -> {
661+
HttpConfiguration configuration = new HttpConfiguration();
662+
configuration.setSendServerVersion(false);
663+
Arrays.stream(server.getConnectors())
664+
.filter(connector -> connector instanceof ServerConnector)
665+
.map(ServerConnector.class::cast)
666+
.forEach(connector -> {
667+
connector.addConnectionFactory(new HTTP2CServerConnectionFactory(configuration));
668+
});
669+
};
670+
}
671+
----
672+
673+
For Netty, we need to add `h2c` as a supported protocol:
674+
675+
[source,java,indent=0,subs="verbatim,quotes,attributes"]
676+
----
677+
@Bean
678+
public NettyServerCustomizer serverCustomizer() {
679+
return (server) -> server.protocol(HttpProtocol.H2C);
680+
}
681+
----
682+
683+
For Undertow, we need to enable the HTTP2 option:
684+
685+
[source,java,indent=0,subs="verbatim,quotes,attributes"]
686+
----
687+
@Bean
688+
public UndertowBuilderCustomizer builderCustomizer() {
689+
return (builder) -> {
690+
builder.setServerOption(ENABLE_HTTP2, true);
691+
};
692+
}
693+
----
694+
695+
696+
697+
640698
[[howto-configure-webserver]]
641699
=== Configure the Web Server
642700
Generally, you should first consider using one of the many available configuration keys and customize your web server by adding new entries in your `application.properties` (or `application.yml`, or environment, etc. see "`<<howto-discover-build-in-options-for-external-properties>>`").

spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\
167167
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\
168168
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\
169169
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,\
170+
org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\
170171
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
171172

172173
# AutoConfigureWebServiceClient

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestAutoConfigurationIntegrationTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration;
2727
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
2828
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration;
29+
import org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration;
2930
import org.springframework.context.ApplicationContext;
3031
import org.springframework.core.task.AsyncTaskExecutor;
3132
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
@@ -88,4 +89,9 @@ void oAuth2ResourceServerAutoConfigurationWasImported() {
8889
assertThat(this.applicationContext).has(importedAutoConfiguration(OAuth2ResourceServerAutoConfiguration.class));
8990
}
9091

92+
@Test
93+
void httpEncodingAutoConfigurationWasImported() {
94+
assertThat(this.applicationContext).has(importedAutoConfiguration(HttpEncodingAutoConfiguration.class));
95+
}
96+
9197
}

0 commit comments

Comments
 (0)