Search in sources :

Example 1 with DefaultBootstrapContext

use of org.springframework.boot.DefaultBootstrapContext in project spring-boot by spring-projects.

the class DelegatingApplicationListenerTests method orderedInitialize.

@Test
void orderedInitialize() {
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "context.listener.classes=" + MockInitB.class.getName() + "," + MockInitA.class.getName());
    this.listener.onApplicationEvent(new ApplicationEnvironmentPreparedEvent(new DefaultBootstrapContext(), new SpringApplication(), new String[0], this.context.getEnvironment()));
    this.context.getBeanFactory().registerSingleton("testListener", this.listener);
    this.context.refresh();
    assertThat(this.context.getBeanFactory().getSingleton("a")).isEqualTo("a");
    assertThat(this.context.getBeanFactory().getSingleton("b")).isEqualTo("b");
}
Also used : DefaultBootstrapContext(org.springframework.boot.DefaultBootstrapContext) SpringApplication(org.springframework.boot.SpringApplication) ApplicationEnvironmentPreparedEvent(org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultBootstrapContext

use of org.springframework.boot.DefaultBootstrapContext in project spring-boot by spring-projects.

the class ConfigDataApplicationContextInitializer method initialize.

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    ConfigurableEnvironment environment = applicationContext.getEnvironment();
    RandomValuePropertySource.addToEnvironment(environment);
    DefaultBootstrapContext bootstrapContext = new DefaultBootstrapContext();
    ConfigDataEnvironmentPostProcessor.applyTo(environment, applicationContext, bootstrapContext);
    bootstrapContext.close(applicationContext);
    DefaultPropertiesPropertySource.moveToEnd(environment);
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) DefaultBootstrapContext(org.springframework.boot.DefaultBootstrapContext)

Example 3 with DefaultBootstrapContext

use of org.springframework.boot.DefaultBootstrapContext in project spring-boot by spring-projects.

the class ConfigDataEnvironmentPostProcessor method applyTo.

/**
 * Apply {@link ConfigData} post-processing to an existing {@link Environment}. This
 * method can be useful when working with an {@link Environment} that has been created
 * directly and not necessarily as part of a {@link SpringApplication}.
 * @param environment the environment to apply {@link ConfigData} to
 * @param resourceLoader the resource loader to use
 * @param bootstrapContext the bootstrap context to use or {@code null} to use a
 * throw-away context
 * @param additionalProfiles any additional profiles that should be applied
 * @param environmentUpdateListener optional
 * {@link ConfigDataEnvironmentUpdateListener} that can be used to track
 * {@link Environment} updates.
 */
public static void applyTo(ConfigurableEnvironment environment, ResourceLoader resourceLoader, ConfigurableBootstrapContext bootstrapContext, Collection<String> additionalProfiles, ConfigDataEnvironmentUpdateListener environmentUpdateListener) {
    DeferredLogFactory logFactory = Supplier::get;
    bootstrapContext = (bootstrapContext != null) ? bootstrapContext : new DefaultBootstrapContext();
    ConfigDataEnvironmentPostProcessor postProcessor = new ConfigDataEnvironmentPostProcessor(logFactory, bootstrapContext, environmentUpdateListener);
    postProcessor.postProcessEnvironment(environment, resourceLoader, additionalProfiles);
}
Also used : DefaultBootstrapContext(org.springframework.boot.DefaultBootstrapContext) DeferredLogFactory(org.springframework.boot.logging.DeferredLogFactory)

Example 4 with DefaultBootstrapContext

use of org.springframework.boot.DefaultBootstrapContext in project spring-boot by spring-projects.

the class ConfigDataEnvironmentPostProcessor method applyTo.

/**
 * Apply {@link ConfigData} post-processing to an existing {@link Environment}. This
 * method can be useful when working with an {@link Environment} that has been created
 * directly and not necessarily as part of a {@link SpringApplication}.
 * @param environment the environment to apply {@link ConfigData} to
 * @param resourceLoader the resource loader to use
 * @param bootstrapContext the bootstrap context to use or {@code null} to use a
 * throw-away context
 * @param additionalProfiles any additional profiles that should be applied
 */
public static void applyTo(ConfigurableEnvironment environment, ResourceLoader resourceLoader, ConfigurableBootstrapContext bootstrapContext, Collection<String> additionalProfiles) {
    DeferredLogFactory logFactory = Supplier::get;
    bootstrapContext = (bootstrapContext != null) ? bootstrapContext : new DefaultBootstrapContext();
    ConfigDataEnvironmentPostProcessor postProcessor = new ConfigDataEnvironmentPostProcessor(logFactory, bootstrapContext);
    postProcessor.postProcessEnvironment(environment, resourceLoader, additionalProfiles);
}
Also used : DefaultBootstrapContext(org.springframework.boot.DefaultBootstrapContext) DeferredLogFactory(org.springframework.boot.logging.DeferredLogFactory)

Example 5 with DefaultBootstrapContext

use of org.springframework.boot.DefaultBootstrapContext in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method withNoEnvironment.

@Test
void withNoEnvironment() {
    File file = new File(this.tempDir, "pid");
    ApplicationPidFileWriter listener = new ApplicationPidFileWriter(file);
    listener.setTriggerEventType(ApplicationStartingEvent.class);
    listener.onApplicationEvent(new ApplicationStartingEvent(new DefaultBootstrapContext(), new SpringApplication(), new String[] {}));
    assertThat(contentOf(file)).isNotEmpty();
}
Also used : DefaultBootstrapContext(org.springframework.boot.DefaultBootstrapContext) SpringApplication(org.springframework.boot.SpringApplication) ApplicationStartingEvent(org.springframework.boot.context.event.ApplicationStartingEvent) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultBootstrapContext (org.springframework.boot.DefaultBootstrapContext)7 SpringApplication (org.springframework.boot.SpringApplication)4 Test (org.junit.jupiter.api.Test)3 ApplicationEnvironmentPreparedEvent (org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent)2 ApplicationStartingEvent (org.springframework.boot.context.event.ApplicationStartingEvent)2 DeferredLogFactory (org.springframework.boot.logging.DeferredLogFactory)2 File (java.io.File)1 ApplicationFailedEvent (org.springframework.boot.context.event.ApplicationFailedEvent)1 ApplicationPreparedEvent (org.springframework.boot.context.event.ApplicationPreparedEvent)1 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1