Search in sources :

Example 1 with WebServerGracefulShutdownLifecycle

use of org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle in project spring-boot by spring-projects.

the class ServletWebServerApplicationContext method createWebServer.

private void createWebServer() {
    WebServer webServer = this.webServer;
    ServletContext servletContext = getServletContext();
    if (webServer == null && servletContext == null) {
        StartupStep createWebServer = this.getApplicationStartup().start("spring.boot.webserver.create");
        ServletWebServerFactory factory = getWebServerFactory();
        createWebServer.tag("factory", factory.getClass().toString());
        this.webServer = factory.getWebServer(getSelfInitializer());
        createWebServer.end();
        getBeanFactory().registerSingleton("webServerGracefulShutdown", new WebServerGracefulShutdownLifecycle(this.webServer));
        getBeanFactory().registerSingleton("webServerStartStop", new WebServerStartStopLifecycle(this, this.webServer));
    } else if (servletContext != null) {
        try {
            getSelfInitializer().onStartup(servletContext);
        } catch (ServletException ex) {
            throw new ApplicationContextException("Cannot initialize servlet context", ex);
        }
    }
    initPropertySources();
}
Also used : ServletException(jakarta.servlet.ServletException) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) WebServer(org.springframework.boot.web.server.WebServer) StartupStep(org.springframework.core.metrics.StartupStep) WebServerGracefulShutdownLifecycle(org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle) ServletContext(jakarta.servlet.ServletContext) ApplicationContextException(org.springframework.context.ApplicationContextException)

Example 2 with WebServerGracefulShutdownLifecycle

use of org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle in project spring-boot by spring-projects.

the class ReactiveWebServerApplicationContext method createWebServer.

private void createWebServer() {
    WebServerManager serverManager = this.serverManager;
    if (serverManager == null) {
        StartupStep createWebServer = this.getApplicationStartup().start("spring.boot.webserver.create");
        String webServerFactoryBeanName = getWebServerFactoryBeanName();
        ReactiveWebServerFactory webServerFactory = getWebServerFactory(webServerFactoryBeanName);
        createWebServer.tag("factory", webServerFactory.getClass().toString());
        boolean lazyInit = getBeanFactory().getBeanDefinition(webServerFactoryBeanName).isLazyInit();
        this.serverManager = new WebServerManager(this, webServerFactory, this::getHttpHandler, lazyInit);
        getBeanFactory().registerSingleton("webServerGracefulShutdown", new WebServerGracefulShutdownLifecycle(this.serverManager.getWebServer()));
        getBeanFactory().registerSingleton("webServerStartStop", new WebServerStartStopLifecycle(this.serverManager));
        createWebServer.end();
    }
    initPropertySources();
}
Also used : StartupStep(org.springframework.core.metrics.StartupStep) WebServerGracefulShutdownLifecycle(org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle) ReactiveWebServerFactory(org.springframework.boot.web.reactive.server.ReactiveWebServerFactory)

Aggregations

WebServerGracefulShutdownLifecycle (org.springframework.boot.web.context.WebServerGracefulShutdownLifecycle)2 StartupStep (org.springframework.core.metrics.StartupStep)2 ServletContext (jakarta.servlet.ServletContext)1 ServletException (jakarta.servlet.ServletException)1 ReactiveWebServerFactory (org.springframework.boot.web.reactive.server.ReactiveWebServerFactory)1 WebServer (org.springframework.boot.web.server.WebServer)1 ServletWebServerFactory (org.springframework.boot.web.servlet.server.ServletWebServerFactory)1 ApplicationContextException (org.springframework.context.ApplicationContextException)1