Skip to content

Commit 5b80dd8

Browse files
committed
Merge branch '2.7.x' into 3.0.x
Closes gh-38026
2 parents 5db85a8 + 9a23e13 commit 5b80dd8

File tree

5 files changed

+173
-0
lines changed

5 files changed

+173
-0
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/reactive.adoc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,52 @@ By default, the embedded server listens for HTTP requests on port 8080.
250250

251251

252252

253+
[[web.reactive.reactive-server.customizing]]
254+
==== Customizing Reactive Servers
255+
Common reactive web server settings can be configured by using Spring `Environment` properties.
256+
Usually, you would define the properties in your `application.properties` or `application.yaml` file.
257+
258+
Common server settings include:
259+
260+
* Network settings: Listen port for incoming HTTP requests (`server.port`), interface address to bind to `server.address`, and so on.
261+
* Error management: Location of the error page (`server.error.path`) and so on.
262+
* <<howto#howto.webserver.configure-ssl,SSL>>
263+
* <<howto#howto.webserver.enable-response-compression,HTTP compression>>
264+
265+
Spring Boot tries as much as possible to expose common settings, but this is not always possible.
266+
For those cases, dedicated namespaces such as `server.netty.*` offer server-specific customizations.
267+
268+
TIP: See the {spring-boot-autoconfigure-module-code}/web/ServerProperties.java[`ServerProperties`] class for a complete list.
269+
270+
271+
272+
[[web.reactive.reactive-server.customizing.programmatic]]
273+
===== Programmatic Customization
274+
If you need to programmatically configure your reactive web server, you can register a Spring bean that implements the `WebServerFactoryCustomizer` interface.
275+
`WebServerFactoryCustomizer` provides access to the `ConfigurableReactiveWebServerFactory`, which includes numerous customization setter methods.
276+
The following example shows programmatically setting the port:
277+
278+
include::code:MyWebServerFactoryCustomizer[]
279+
280+
`JettyReactiveWebServerFactory`, `NettyReactiveWebServerFactory`, `TomcatReactiveWebServerFactory`, and `UndertowServletWebServerFactory` are dedicated variants of `ConfigurableReactiveWebServerFactory` that have additional customization setter methods for Jetty, Reactor Netty, Tomcat, and Undertow respectively.
281+
The following example shows how to customize `NettyReactiveWebServerFactory` that provides access to Reactor Netty-specific configuration options:
282+
283+
include::code:MyNettyWebServerFactoryCustomizer[]
284+
285+
286+
287+
[[web.reactive.reactive-server.customizing.direct]]
288+
===== Customizing ConfigurableReactiveWebServerFactory Directly
289+
For more advanced use cases that require you to extend from `ReactiveWebServerFactory`, you can expose a bean of such type yourself.
290+
291+
Setters are provided for many configuration options.
292+
Several protected method "`hooks`" are also provided should you need to do something more exotic.
293+
See the {spring-boot-module-api}/web/reactive/server/ConfigurableReactiveWebServerFactory.html[source code documentation] for details.
294+
295+
NOTE: Auto-configured customizers are still applied on your custom factory, so use that option carefully.
296+
297+
298+
253299
[[web.reactive.reactive-server-resources-configuration]]
254300
=== Reactive Server Resources Configuration
255301
When auto-configuring a Reactor Netty or Jetty server, Spring Boot will create specific beans that will provide HTTP resources to the server instance: `ReactorResourceFactory` or `JettyResourceFactory`.
@@ -262,3 +308,5 @@ By default, those resources will be also shared with the Reactor Netty and Jetty
262308
Developers can override the resource configuration for Jetty and Reactor Netty by providing a custom `ReactorResourceFactory` or `JettyResourceFactory` bean - this will be applied to both clients and servers.
263309

264310
You can learn more about the resource configuration on the client side in the <<io#io.rest-client.webclient.runtime, WebClient Runtime section>>.
311+
312+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2023 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.web.reactive.reactiveserver.customizing.programmatic;
18+
19+
import java.time.Duration;
20+
21+
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
22+
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
23+
import org.springframework.stereotype.Component;
24+
25+
@Component
26+
public class MyNettyWebServerFactoryCustomizer implements WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
27+
28+
@Override
29+
public void customize(NettyReactiveWebServerFactory factory) {
30+
factory.addServerCustomizers((server) -> server.idleTimeout(Duration.ofSeconds(20)));
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2012-2023 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.web.reactive.reactiveserver.customizing.programmatic;
18+
19+
import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory;
20+
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
21+
import org.springframework.stereotype.Component;
22+
23+
@Component
24+
public class MyWebServerFactoryCustomizer implements WebServerFactoryCustomizer<ConfigurableReactiveWebServerFactory> {
25+
26+
@Override
27+
public void customize(ConfigurableReactiveWebServerFactory server) {
28+
server.setPort(9000);
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2012-2023 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.web.reactive.reactiveserver.customizing.programmatic
18+
19+
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
20+
import org.springframework.boot.web.server.WebServerFactoryCustomizer
21+
import org.springframework.stereotype.Component
22+
import java.time.Duration
23+
24+
@Component
25+
class MyNettyWebServerFactoryCustomizer : WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
26+
27+
override fun customize(factory: NettyReactiveWebServerFactory) {
28+
factory.addServerCustomizers({ server -> server.idleTimeout(Duration.ofSeconds(20)) })
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2012-2023 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.web.reactive.reactiveserver.customizing.programmatic
18+
19+
import org.springframework.boot.web.server.WebServerFactoryCustomizer
20+
import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory
21+
import org.springframework.stereotype.Component
22+
23+
@Component
24+
class MyWebServerFactoryCustomizer : WebServerFactoryCustomizer<ConfigurableReactiveWebServerFactory> {
25+
26+
override fun customize(server: ConfigurableReactiveWebServerFactory) {
27+
server.setPort(9000)
28+
}
29+
30+
}

0 commit comments

Comments
 (0)