Skip to content

Commit 5c14e85

Browse files
committed
Merge pull request #22898 from johncfranco
* pr/22898: Polish "Harmonize Discover the HTTP Port at Runtime How-To" Harmonize Discover the HTTP Port at Runtime How-To Closes gh-22898
2 parents cdbb7f4 + ee2363f commit 5c14e85

File tree

1 file changed

+2
-5
lines changed
  • spring-boot-project/spring-boot-docs/src/main/asciidoc

1 file changed

+2
-5
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ To scan for a free port (using OS natives to prevent clashes) use `server.port=0
497497

498498
[[howto-discover-the-http-port-at-runtime]]
499499
=== Discover the HTTP Port at Runtime
500-
You can access the port the server is running on from log output or from the `ServletWebServerApplicationContext` through its `WebServer`.
501-
The best way to get that and be sure that it has been initialized is to add a `@Bean` of type `ApplicationListener<ServletWebServerInitializedEvent>` and pull the container out of the event when it is published.
500+
You can access the port the server is running on from log output or from the `WebServerApplicationContext` through its `WebServer`.
501+
The best way to get that and be sure it has been initialized is to add a `@Bean` of type `ApplicationListener<WebServerInitializedEvent>` and pull the container out of the event when it is published.
502502

503503
Tests that use `@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)` can also inject the actual port into a field by using the `@LocalServerPort` annotation, as shown in the following example:
504504

@@ -507,9 +507,6 @@ Tests that use `@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)` can
507507
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
508508
public class MyWebIntegrationTests {
509509
510-
@Autowired
511-
ServletWebServerApplicationContext server;
512-
513510
@LocalServerPort
514511
int port;
515512

0 commit comments

Comments
 (0)