Class WebServerPortFileWriter
- java.lang.Object
- org.springframework.boot.web.context.WebServerPortFileWriter
- All Implemented Interfaces:
EventListener
,org.springframework.context.ApplicationListener<WebServerInitializedEvent>
public class WebServerPortFileWriter extends Object implements org.springframework.context.ApplicationListener<WebServerInitializedEvent>
AnApplicationListener
that saves embedded server port and management port into file. This application listener will be triggered whenever the server starts, and the file name can be overridden at runtime with a System property or environment variable named "PORTFILE" or "portfile".- Since:
- 2.0.0
Constructor Summary
Constructors Constructor Description WebServerPortFileWriter()
Create a newWebServerPortFileWriter
instance using the filename 'application.port'.WebServerPortFileWriter(File file)
Create a newWebServerPortFileWriter
instance with a specified file.WebServerPortFileWriter(String filename)
Create a newWebServerPortFileWriter
instance with a specified filename.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected File
getPortFile(org.springframework.context.ApplicationContext applicationContext)
Return the actual port file that should be written for the given application context.void
onApplicationEvent(WebServerInitializedEvent event)
Constructor Detail
WebServerPortFileWriter
public WebServerPortFileWriter()
Create a newWebServerPortFileWriter
instance using the filename 'application.port'.
WebServerPortFileWriter
public WebServerPortFileWriter(String filename)
Create a newWebServerPortFileWriter
instance with a specified filename.- Parameters:
filename
- the name of file containing port
WebServerPortFileWriter
public WebServerPortFileWriter(File file)
Create a newWebServerPortFileWriter
instance with a specified file.- Parameters:
file
- the file containing port
Method Detail
onApplicationEvent
public void onApplicationEvent(WebServerInitializedEvent event)
- Specified by:
onApplicationEvent
in interfaceorg.springframework.context.ApplicationListener<WebServerInitializedEvent>
getPortFile
protected File getPortFile(org.springframework.context.ApplicationContext applicationContext)
Return the actual port file that should be written for the given application context. The default implementation builds a file from the source file and the application context namespace if available.- Parameters:
applicationContext
- the source application context- Returns:
- the file that should be written