Example usage for org.springframework.boot.web.servlet.support ServletContextApplicationContextInitializer ServletContextApplicationContextInitializer

List of usage examples for org.springframework.boot.web.servlet.support ServletContextApplicationContextInitializer ServletContextApplicationContextInitializer

Introduction

In this page you can find the example usage for org.springframework.boot.web.servlet.support ServletContextApplicationContextInitializer ServletContextApplicationContextInitializer.

Prototype

public ServletContextApplicationContextInitializer(ServletContext servletContext) 

Source Link

Document

Create a new ServletContextApplicationContextInitializer instance.

Usage

From source file:org.springframework.boot.web.servlet.support.SpringBootServletInitializer.java

protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) {
    SpringApplicationBuilder builder = createSpringApplicationBuilder();
    builder.main(getClass());/*from w w w.j  av a 2 s .  c  om*/
    ApplicationContext parent = getExistingRootWebApplicationContext(servletContext);
    if (parent != null) {
        this.logger.info("Root context already created (using as parent).");
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null);
        builder.initializers(new ParentContextApplicationContextInitializer(parent));
    }
    builder.initializers(new ServletContextApplicationContextInitializer(servletContext));
    builder.contextClass(AnnotationConfigServletWebServerApplicationContext.class);
    builder = configure(builder);
    builder.listeners(new WebEnvironmentPropertySourceInitializer(servletContext));
    SpringApplication application = builder.build();
    if (application.getAllSources().isEmpty()
            && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) {
        application.addPrimarySources(Collections.singleton(getClass()));
    }
    Assert.state(!application.getAllSources().isEmpty(),
            "No SpringApplication sources have been defined. Either override the "
                    + "configure method or add an @Configuration annotation");
    // Ensure error pages are registered
    if (this.registerErrorPageFilter) {
        application.addPrimarySources(Collections.singleton(ErrorPageFilterConfiguration.class));
    }
    return run(application);
}