Example usage for org.springframework.boot.builder SpringApplicationBuilder SpringApplicationBuilder

List of usage examples for org.springframework.boot.builder SpringApplicationBuilder SpringApplicationBuilder

Introduction

In this page you can find the example usage for org.springframework.boot.builder SpringApplicationBuilder SpringApplicationBuilder.

Prototype

SpringApplicationBuilder

Source Link

Usage

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

protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) {
    ApplicationContext parent = null;//from   w ww .ja v a  2s . com
    Object object = servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (object instanceof ApplicationContext) {
        this.logger.info("Root context already created (using as parent).");
        parent = (ApplicationContext) object;
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null);
    }
    SpringApplicationBuilder application = new SpringApplicationBuilder();
    if (parent != null) {
        application.initializers(new ParentContextApplicationContextInitializer(parent));
    }
    application.initializers(new ServletContextApplicationContextInitializer(servletContext));
    application.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class);
    application = configure(application);
    return (WebApplicationContext) application.run();
}

From source file:org.springframework.cloud.cloudfoundry.discovery.CloudFoundryAutoConfigurationTest.java

@Before
public void setUp() {

    String hiServiceServiceId = "foo-service";

    Object vcapAppl = "{\"limits\":{\"mem\":1024,\"disk\":1024,\"fds\":16384},\"application_version\":"
            + "\"36eff082-96d6-498f-8214-508fda72ba65\",\"application_name\":\"" + hiServiceServiceId
            + "\",\"application_uris\"" + ":[\"" + hiServiceServiceId
            + ".cfapps.io\"],\"version\":\"36eff082-96d6-498f-8214-508fda72ba65\",\"name\":"
            + "\"hi-service\",\"space_name\":\"joshlong\",\"space_id\":\"e0cd969c-3461-41ae-abde-4e11bb5acbd1\","
            + "\"uris\":[\"hi-service.cfapps.io\"],\"users\":null,\"application_id\":\"af350f7c-88c4-4e35-a04e-698a1dbc7354\","
            + "\"instance_id\":\"e4843ca23bd947b28e6d4cb3f9b92cbb\",\"instance_index\":0,\"host\":\"0.0.0.0\",\"port\":61590,"
            + "\"started_at\":\"2015-05-07 20:00:10 +0000\",\"started_at_timestamp\":1431028810,\"start\":\"2015-05-07 20:00:10 +0000\","
            + "\"state_timestamp\":1431028810}";

    this.context = new SpringApplicationBuilder()
            .properties(Collections.singletonMap("VCAP_APPLICATION", vcapAppl))
            .sources(SimpleConfiguration.class).run();
}

From source file:org.springframework.xd.module.core.SimpleModule.java

public SimpleModule(ModuleDescriptor descriptor, ModuleDeploymentProperties deploymentProperties,
        ClassLoader classLoader, ModuleOptions moduleOptions) {
    super(descriptor, deploymentProperties);
    this.moduleOptions = moduleOptions;
    application = new SpringApplicationBuilder().sources(PropertyPlaceholderAutoConfiguration.class).web(false)
            .showBanner(false);//from  w  w w  . j ava  2  s .com

    this.classLoader = classLoader;

    if (classLoader != null) {
        application.resourceLoader(new PathMatchingResourcePatternResolver(classLoader));
    }

    // Also add options as properties for now, b/c other parts of the system
    // (eg type conversion plugin) expects it
    this.properties.putAll(moduleOptionsToProperties(moduleOptions));

    application.profiles(moduleOptions.profilesToActivate());

    this.configureModuleApplicationContext((SimpleModuleDefinition) this.getDescriptor().getModuleDefinition());
}

From source file:org.springframework.xd.module.SimpleModule.java

public SimpleModule(ModuleDefinition definition, DeploymentMetadata metadata, ClassLoader classLoader) {
    super(definition, metadata);
    application = new SpringApplicationBuilder().sources(PropertyPlaceholderAutoConfiguration.class).web(false);
    environment = new StandardEnvironment();
    if (classLoader != null) {
        application.resourceLoader(new PathMatchingResourcePatternResolver(classLoader));
    }/*from  ww  w.ja v a  2 s.  com*/
    if (definition != null) {
        if (definition.getResource().isReadable()) {
            this.addComponents(definition.getResource());
        }
        if (definition.getProperties() != null) {
            this.addProperties(definition.getProperties());
        }
    }
}