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");
}
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);
}
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);
}
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);
}
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();
}
Aggregations