diff --git a/documentation/spring-boot-docs/build.gradle b/documentation/spring-boot-docs/build.gradle index 449baac2fae..02501fd10c5 100644 --- a/documentation/spring-boot-docs/build.gradle +++ b/documentation/spring-boot-docs/build.gradle @@ -118,6 +118,7 @@ dependencies { implementation(project(path: ":module:spring-boot-jackson")) implementation(project(path: ":module:spring-boot-jdbc")) implementation(project(path: ":module:spring-boot-jdbc-test")) + implementation(project(path: ":module:spring-boot-jetty")) implementation(project(path: ":module:spring-boot-jooq-test")) implementation(project(path: ":module:spring-boot-jpa")) implementation(project(path: ":module:spring-boot-jms")) diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc index 07285422bff..7ecb54225ae 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc @@ -679,8 +679,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-response-compression[#how-to-enable-http-response-compression] * xref:how-to:webserver.adoc#howto.webserver.enable-response-compression[#howto.webserver.enable-response-compression] * xref:how-to:webserver.adoc#howto.webserver.enable-tomcat-mbean-registry[#howto-enable-tomcat-mbean-registry] diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc index 09f4b0f79fc..54e8ef80479 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc @@ -547,8 +547,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.tomcat.servlet.TomcatServletWebServerFactory[], which can allow multiple connectors, including HTTP and HTTPS connectors, as shown in the following example: @@ -556,6 +561,15 @@ include-code::MyTomcatConfiguration[] +[[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[] on the javadoc:org.springframework.boot.jetty.ConfigurableJettyWebServerFactory[], as shown in the following example: + +include-code::MyJettyConfiguration[] + + + [[howto.webserver.enable-tomcat-mbean-registry]] == Enable Tomcat's MBean Registry diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.java new file mode 100644 index 00000000000..57998709e0d --- /dev/null +++ b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.java @@ -0,0 +1,38 @@ +/* + * 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.ServerConnector; + +import org.springframework.boot.jetty.ConfigurableJettyWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +public class MyJettyConfiguration { + + @Bean + public WebServerFactoryCustomizer connectorCustomizer() { + return (jetty) -> jetty.addServerCustomizers((server) -> { + ServerConnector connector = new ServerConnector(server); + connector.setPort(8081); + server.addConnector(connector); + }); + } + +} diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.java similarity index 98% rename from documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java rename to documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.java index 4a75b16c4b5..e7a7b8454e8 100644 --- a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java +++ b/documentation/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/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/jetty/MyJettyConfiguration.kt new file mode 100644 index 00000000000..9475df1bf71 --- /dev/null +++ b/documentation/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.jetty.ConfigurableJettyWebServerFactory +import org.springframework.boot.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/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.kt similarity index 98% rename from documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt rename to documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.kt index 92e7aa6fc70..f334729439f 100644 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt +++ b/documentation/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.server.WebServerFactoryCustomizer @@ -39,4 +39,3 @@ class MyTomcatConfiguration { } } -