Example usage for org.springframework.boot.web.context WebServerInitializedEvent getApplicationContext

List of usage examples for org.springframework.boot.web.context WebServerInitializedEvent getApplicationContext

Introduction

In this page you can find the example usage for org.springframework.boot.web.context WebServerInitializedEvent getApplicationContext.

Prototype

public abstract WebServerApplicationContext getApplicationContext();

Source Link

Document

Access the application context that the server was created in.

Usage

From source file:org.springframework.boot.web.context.WebServerPortFileWriter.java

@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    File portFile = getPortFile(event.getApplicationContext());
    try {//  w ww  .  j a  v a2s  . c  om
        String port = String.valueOf(event.getWebServer().getPort());
        createParentFolder(portFile);
        FileCopyUtils.copy(port.getBytes(), portFile);
        portFile.deleteOnExit();
    } catch (Exception ex) {
        logger.warn(String.format("Cannot create port file %s", this.file));
    }
}