From 796ac7870d74ab908eb68e4f6c8294aec603a912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Sat, 25 Apr 2026 10:53:17 +0200 Subject: [PATCH] Polish "Document configuring multiple connectors with Jetty" See gh-17144 --- .../antora/modules/ROOT/pages/redirect.adoc | 4 +- .../modules/how-to/pages/webserver.adoc | 15 ++++--- .../jetty}/MyJettyConfiguration.java | 2 +- .../tomcat}/MyTomcatConfiguration.java | 2 +- .../jetty/MyJettyConfiguration.kt | 41 +++++++++++++++++++ .../tomcat}/MyTomcatConfiguration.kt | 3 +- 6 files changed, 56 insertions(+), 11 deletions(-) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/{enablemultipleconnectorsinjetty => enablemultipleconnectors/jetty}/MyJettyConfiguration.java (98%) rename spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/{enablemultipleconnectorsintomcat => enablemultipleconnectors/tomcat}/MyTomcatConfiguration.java (98%) create mode 100644 spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.kt rename spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/{enablemultipleconnectorsintomcat => enablemultipleconnectors/tomcat}/MyTomcatConfiguration.kt (98%) diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc index 36b673af5e8..a103d747272 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc @@ -697,8 +697,8 @@ * xref:how-to:webserver.adoc#howto.webserver.disable[#howto.webserver.disable] * xref:how-to:webserver.adoc#howto.webserver.discover-port[#howto-discover-the-http-port-at-runtime] * xref:how-to:webserver.adoc#howto.webserver.discover-port[#howto.webserver.discover-port] -* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-connectors-in-tomcat[#howto-enable-multiple-connectors-in-tomcat] -* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-connectors-in-tomcat[#howto.webserver.enable-multiple-connectors-in-tomcat] +* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-connectors.tomcat[#howto-enable-multiple-connectors-in-tomcat] +* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-connectors.tomcat[#howto.webserver.enable-multiple-connectors-in-tomcat] * xref:how-to:webserver.adoc#howto.webserver.enable-multiple-listeners-in-undertow[#howto-enable-multiple-listeners-in-undertow] * xref:how-to:webserver.adoc#howto.webserver.enable-multiple-listeners-in-undertow[#howto.webserver.enable-multiple-listeners-in-undertow] * xref:how-to:webserver.adoc#howto.webserver.enable-response-compression[#how-to-enable-http-response-compression] diff --git a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc index 05b6ec3a2e0..05b869d7fb8 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc @@ -511,8 +511,13 @@ You can take complete control of the configuration of Tomcat's javadoc:org.apach -[[howto.webserver.enable-multiple-connectors-in-tomcat]] -== Enable Multiple Connectors with Tomcat +[[howto.webserver.enable-multiple-connectors]] +== Enable Multiple Connectors + + + +[[howto.webserver.enable-multiple-connectors.tomcat]] +=== Multiple Connectors with Tomcat You can add an javadoc:org.apache.catalina.connector.Connector[] to the javadoc:org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory[], which can allow multiple connectors, including HTTP and HTTPS connectors, as shown in the following example: @@ -520,10 +525,10 @@ include-code::MyTomcatConfiguration[] -[[howto.webserver.enable-multiple-connectors-in-jetty]] -== Enable Multiple Connectors with Jetty +[[howto.webserver.enable-multiple-connectors.jetty]] +=== Multiple Connectors with Jetty -You can register additional Jetty javadoc:org.eclipse.jetty.server.Connector[] instances by adding a javadoc:org.springframework.boot.jetty.JettyServerCustomizer[] to the javadoc:org.springframework.boot.jetty.ConfigurableJettyWebServerFactory[], as shown in the following example: +You can register additional Jetty javadoc:org.eclipse.jetty.server.Connector[] instances by adding a javadoc:org.springframework.boot.jetty.JettyServerCustomizer[] on the javadoc:org.springframework.boot.jetty.ConfigurableJettyWebServerFactory[], as shown in the following example: include-code::MyJettyConfiguration[] diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsinjetty/MyJettyConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.java similarity index 98% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsinjetty/MyJettyConfiguration.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.java index 320647d9bb6..14e333b4557 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsinjetty/MyJettyConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsinjetty; +package org.springframework.boot.docs.howto.webserver.enablemultipleconnectors.jetty; import org.eclipse.jetty.server.ServerConnector; diff --git a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.java similarity index 98% rename from spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java rename to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.java index 40d0cbe8147..a5bdb5f278c 100644 --- a/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java +++ b/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat; +package org.springframework.boot.docs.howto.webserver.enablemultipleconnectors.tomcat; import org.apache.catalina.connector.Connector; diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.kt new file mode 100644 index 00000000000..23c681ca33c --- /dev/null +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.docs.howto.webserver.enablemultipleconnectors.jetty + +import org.eclipse.jetty.server.Server +import org.eclipse.jetty.server.ServerConnector +import org.springframework.boot.web.embedded.jetty.ConfigurableJettyWebServerFactory +import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer +import org.springframework.boot.web.server.WebServerFactoryCustomizer +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration(proxyBeanMethods = false) +class MyJettyConfiguration { + + @Bean + fun connectorCustomizer(): WebServerFactoryCustomizer { + return WebServerFactoryCustomizer { jetty: ConfigurableJettyWebServerFactory -> + jetty.addServerCustomizers(JettyServerCustomizer { server: Server -> + val connector = ServerConnector(server) + connector.setPort(8081) + server.addConnector(connector) + }) + } + } + +} diff --git a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.kt similarity index 98% rename from spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt rename to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.kt index 2612b735e39..938be5a4e67 100644 --- a/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt +++ b/spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat +package org.springframework.boot.docs.howto.webserver.enablemultipleconnectors.tomcat import org.apache.catalina.connector.Connector import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory @@ -41,4 +41,3 @@ class MyTomcatConfiguration { } } -