Example usage for org.springframework.boot SpringApplication getSources

List of usage examples for org.springframework.boot SpringApplication getSources

Introduction

In this page you can find the example usage for org.springframework.boot SpringApplication getSources.

Prototype

public Set<String> getSources() 

Source Link

Document

Returns a mutable set of the sources that will be added to an ApplicationContext when #run(String) is called.

Usage

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

protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) {
    SpringApplicationBuilder builder = createSpringApplicationBuilder();
    builder.main(getClass());/*from   ww w . j  ava  2s  .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(AnnotationConfigEmbeddedWebApplicationContext.class);
    builder = configure(builder);
    SpringApplication application = builder.build();
    if (application.getSources().isEmpty()
            && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) {
        application.getSources().add(getClass());
    }
    Assert.state(application.getSources().size() > 0,
            "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.getSources().add(ErrorPageFilter.class);
    }
    return run(application);
}

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

protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) {
    SpringApplicationBuilder builder = createSpringApplicationBuilder();
    builder.main(getClass());/*from   w ww .  ja va 2s.c  o m*/
    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.listeners(new ServletContextApplicationListener(servletContext));
    builder.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class);
    builder = configure(builder);
    SpringApplication application = builder.build();
    if (application.getSources().isEmpty()
            && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) {
        application.getSources().add(getClass());
    }
    Assert.state(!application.getSources().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.getSources().add(ErrorPageFilterConfiguration.class);
    }
    return run(application);
}