From b558537ee603962c26def8da05fbd0c3380a0f51 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Fri, 27 Dec 2013 09:18:09 +0000 Subject: [PATCH] Docs for obtaining server port --- docs/howto.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/howto.md b/docs/howto.md index 4868e2df5f..a34ca53062 100644 --- a/docs/howto.md +++ b/docs/howto.md @@ -423,8 +423,7 @@ can be set with `server.port` (e.g. in `application.properties` or as a System property). Thanks to relaxed binding of `Environment` values you can also use `SERVER_PORT` (e.g. as an OS environment variable). -To scan for a free port (using OS natives to prevent clashes) use -`server.port=0`. To switch off the HTTP endpoints completely, but +To switch off the HTTP endpoints completely, but still create a `WebApplicationContext`, use `server.port=-1` (this is sometimes useful for testing). @@ -432,6 +431,18 @@ For more detail look at the [`ServerProperties`](https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java?source=c) source code. +## Use a Random Unassigned HTTP Port + +To scan for a free port (using OS natives to prevent clashes) use +`server.port=0`. + +## Discover the HTTP Port at Runtime + +You can access the port the server is running on from log output or +from the `EmbeddedWebApplicationContext` via its +`EmbeddedServletContainer` (you can `@Autowired` an +`ApplicationContext` and downcast it to obtain the specific type). + ## Change the HTTP Port or Address of the Actuator Endpoints In a standalone application the Actuator HTTP port defaults to the