Class ServerPortInfoApplicationContextInitializer
- java.lang.Object
- org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
- All Implemented Interfaces:
EventListener
,org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>
,org.springframework.context.ApplicationListener<WebServerInitializedEvent>
public class ServerPortInfoApplicationContextInitializer extends Object implements org.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>, org.springframework.context.ApplicationListener<WebServerInitializedEvent>
ApplicationContextInitializer
that setsEnvironment
properties for the ports thatWebServer
servers are actually listening on. The property "local.server.port" can be injected directly into tests using@Value
or obtained via theEnvironment
.If the
WebServerInitializedEvent
has aserver namespace
, it will be used to construct the property name. For example, the "management" actuator context will have the property name "local.management.port".Properties are automatically propagated up to any parent context.
- Since:
- 2.0.0
Constructor Summary
Constructors Constructor Description ServerPortInfoApplicationContextInitializer()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
initialize(org.springframework.context.ConfigurableApplicationContext applicationContext)
void
onApplicationEvent(WebServerInitializedEvent event)
Constructor Detail
ServerPortInfoApplicationContextInitializer
public ServerPortInfoApplicationContextInitializer()
Method Detail
initialize
public void initialize(org.springframework.context.ConfigurableApplicationContext applicationContext)
- Specified by:
initialize
in interfaceorg.springframework.context.ApplicationContextInitializer<org.springframework.context.ConfigurableApplicationContext>
onApplicationEvent
public void onApplicationEvent(WebServerInitializedEvent event)
- Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<WebServerInitializedEvent>