Skip to content

Commit 2dfcbd7

Browse files
committed
Merge pull request #17144 from zxuhan7
* gh-17144-document-jetty-multiple-connectors: Polish "Document configuring multiple connectors with Jetty" Document configuring multiple connectors with Jetty Closes gh-17144
2 parents 466e11b + 796ac78 commit 2dfcbd7

7 files changed

Lines changed: 100 additions & 7 deletions

File tree

spring-boot-project/spring-boot-docs/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ dependencies {
105105
implementation("org.apache.tomcat.embed:tomcat-embed-core")
106106
implementation("org.assertj:assertj-core")
107107
implementation("org.cache2k:cache2k-spring")
108+
implementation("org.eclipse.jetty:jetty-server")
108109
implementation("org.apache.groovy:groovy")
109110
implementation("org.glassfish.jersey.containers:jersey-container-servlet-core")
110111
implementation("org.glassfish.jersey.core:jersey-server")

spring-boot-project/spring-boot-docs/src/docs/antora/modules/ROOT/pages/redirect.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,8 +697,8 @@
697697
* xref:how-to:webserver.adoc#howto.webserver.disable[#howto.webserver.disable]
698698
* xref:how-to:webserver.adoc#howto.webserver.discover-port[#howto-discover-the-http-port-at-runtime]
699699
* xref:how-to:webserver.adoc#howto.webserver.discover-port[#howto.webserver.discover-port]
700-
* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-connectors-in-tomcat[#howto-enable-multiple-connectors-in-tomcat]
701-
* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-connectors-in-tomcat[#howto.webserver.enable-multiple-connectors-in-tomcat]
700+
* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-connectors.tomcat[#howto-enable-multiple-connectors-in-tomcat]
701+
* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-connectors.tomcat[#howto.webserver.enable-multiple-connectors-in-tomcat]
702702
* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-listeners-in-undertow[#howto-enable-multiple-listeners-in-undertow]
703703
* xref:how-to:webserver.adoc#howto.webserver.enable-multiple-listeners-in-undertow[#howto.webserver.enable-multiple-listeners-in-undertow]
704704
* xref:how-to:webserver.adoc#howto.webserver.enable-response-compression[#how-to-enable-http-response-compression]

spring-boot-project/spring-boot-docs/src/docs/antora/modules/how-to/pages/webserver.adoc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,29 @@ You can take complete control of the configuration of Tomcat's javadoc:org.apach
511511

512512

513513

514-
[[howto.webserver.enable-multiple-connectors-in-tomcat]]
515-
== Enable Multiple Connectors with Tomcat
514+
[[howto.webserver.enable-multiple-connectors]]
515+
== Enable Multiple Connectors
516+
517+
518+
519+
[[howto.webserver.enable-multiple-connectors.tomcat]]
520+
=== Multiple Connectors with Tomcat
516521

517522
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:
518523

519524
include-code::MyTomcatConfiguration[]
520525

521526

522527

528+
[[howto.webserver.enable-multiple-connectors.jetty]]
529+
=== Multiple Connectors with Jetty
530+
531+
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:
532+
533+
include-code::MyJettyConfiguration[]
534+
535+
536+
523537
[[howto.webserver.enable-tomcat-mbean-registry]]
524538
== Enable Tomcat's MBean Registry
525539

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectors.jetty;
18+
19+
import org.eclipse.jetty.server.ServerConnector;
20+
21+
import org.springframework.boot.web.embedded.jetty.ConfigurableJettyWebServerFactory;
22+
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
25+
26+
@Configuration(proxyBeanMethods = false)
27+
public class MyJettyConfiguration {
28+
29+
@Bean
30+
public WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> connectorCustomizer() {
31+
return (jetty) -> jetty.addServerCustomizers((server) -> {
32+
ServerConnector connector = new ServerConnector(server);
33+
connector.setPort(8081);
34+
server.addConnector(connector);
35+
});
36+
}
37+
38+
}

spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.java renamed to spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat;
17+
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectors.tomcat;
1818

1919
import org.apache.catalina.connector.Connector;
2020

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectors.jetty
18+
19+
import org.eclipse.jetty.server.Server
20+
import org.eclipse.jetty.server.ServerConnector
21+
import org.springframework.boot.web.embedded.jetty.ConfigurableJettyWebServerFactory
22+
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer
23+
import org.springframework.boot.web.server.WebServerFactoryCustomizer
24+
import org.springframework.context.annotation.Bean
25+
import org.springframework.context.annotation.Configuration
26+
27+
@Configuration(proxyBeanMethods = false)
28+
class MyJettyConfiguration {
29+
30+
@Bean
31+
fun connectorCustomizer(): WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> {
32+
return WebServerFactoryCustomizer { jetty: ConfigurableJettyWebServerFactory ->
33+
jetty.addServerCustomizers(JettyServerCustomizer { server: Server ->
34+
val connector = ServerConnector(server)
35+
connector.setPort(8081)
36+
server.addConnector(connector)
37+
})
38+
}
39+
}
40+
41+
}

spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectorsintomcat/MyTomcatConfiguration.kt renamed to spring-boot-project/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/howto/webserver/enablemultipleconnectors/tomcat/MyTomcatConfiguration.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectorsintomcat
17+
package org.springframework.boot.docs.howto.webserver.enablemultipleconnectors.tomcat
1818

1919
import org.apache.catalina.connector.Connector
2020
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
@@ -41,4 +41,3 @@ class MyTomcatConfiguration {
4141
}
4242

4343
}
44-

0 commit comments

Comments
 (0)