use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.
the class SpringApplication method prepareContext.
private void prepareContext(DefaultBootstrapContext bootstrapContext, ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner) {
context.setEnvironment(environment);
postProcessApplicationContext(context);
applyInitializers(context);
listeners.contextPrepared(context);
bootstrapContext.close(context);
if (this.logStartupInfo) {
logStartupInfo(context.getParent() == null);
logStartupProfileInfo(context);
}
// Add boot specific singleton beans
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
beanFactory.registerSingleton("springApplicationArguments", applicationArguments);
if (printedBanner != null) {
beanFactory.registerSingleton("springBootBanner", printedBanner);
}
if (beanFactory instanceof AbstractAutowireCapableBeanFactory) {
((AbstractAutowireCapableBeanFactory) beanFactory).setAllowCircularReferences(this.allowCircularReferences);
if (beanFactory instanceof DefaultListableBeanFactory) {
((DefaultListableBeanFactory) beanFactory).setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
}
}
if (this.lazyInitialization) {
context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor());
}
// Load the sources
Set<Object> sources = getAllSources();
Assert.notEmpty(sources, "Sources must not be empty");
load(context, sources.toArray(new Object[0]));
listeners.contextLoaded(context);
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.
the class AbstractApplicationContextRunner method createAndLoadContext.
private C createAndLoadContext() {
C context = this.runnerConfiguration.contextFactory.get();
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
if (beanFactory instanceof AbstractAutowireCapableBeanFactory) {
((AbstractAutowireCapableBeanFactory) beanFactory).setAllowCircularReferences(this.runnerConfiguration.allowCircularReferences);
if (beanFactory instanceof DefaultListableBeanFactory) {
((DefaultListableBeanFactory) beanFactory).setAllowBeanDefinitionOverriding(this.runnerConfiguration.allowBeanDefinitionOverriding);
}
}
try {
configureContext(context);
return context;
} catch (RuntimeException ex) {
context.close();
throw ex;
}
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.
the class SpringApplicationTests method runnersAreCalledAfterStartedIsLoggedAndBeforeApplicationReadyEventIsPublished.
@Test
@SuppressWarnings("unchecked")
void runnersAreCalledAfterStartedIsLoggedAndBeforeApplicationReadyEventIsPublished(CapturedOutput output) throws Exception {
SpringApplication application = new SpringApplication(ExampleConfig.class);
ApplicationRunner applicationRunner = mock(ApplicationRunner.class);
CommandLineRunner commandLineRunner = mock(CommandLineRunner.class);
application.addInitializers((context) -> {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
beanFactory.registerSingleton("commandLineRunner", (CommandLineRunner) (args) -> {
assertThat(output).contains("Started");
commandLineRunner.run(args);
});
beanFactory.registerSingleton("applicationRunner", (ApplicationRunner) (args) -> {
assertThat(output).contains("Started");
applicationRunner.run(args);
});
});
application.setWebApplicationType(WebApplicationType.NONE);
ApplicationListener<ApplicationReadyEvent> eventListener = mock(ApplicationListener.class);
application.addListeners(eventListener);
this.context = application.run();
InOrder applicationRunnerOrder = Mockito.inOrder(eventListener, applicationRunner);
applicationRunnerOrder.verify(applicationRunner).run(any(ApplicationArguments.class));
applicationRunnerOrder.verify(eventListener).onApplicationEvent(any(ApplicationReadyEvent.class));
InOrder commandLineRunnerOrder = Mockito.inOrder(eventListener, commandLineRunner);
commandLineRunnerOrder.verify(commandLineRunner).run();
commandLineRunnerOrder.verify(eventListener).onApplicationEvent(any(ApplicationReadyEvent.class));
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.
the class SessionAutoConfigurationJdbcTests method sessionRepositoryBeansDependOnJdbcSessionDataSourceInitializer.
@Test
void sessionRepositoryBeansDependOnJdbcSessionDataSourceInitializer() {
this.contextRunner.withPropertyValues("spring.session.store-type=jdbc").run((context) -> {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
String[] sessionRepositoryNames = beanFactory.getBeanNamesForType(JdbcIndexedSessionRepository.class);
assertThat(sessionRepositoryNames).isNotEmpty();
for (String sessionRepositoryName : sessionRepositoryNames) {
assertThat(beanFactory.getBeanDefinition(sessionRepositoryName).getDependsOn()).contains("jdbcSessionDataSourceScriptDatabaseInitializer");
}
});
}
use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.
the class SessionAutoConfigurationJdbcTests method sessionRepositoryBeansDependOnLiquibase.
@Test
void sessionRepositoryBeansDependOnLiquibase() {
this.contextRunner.withConfiguration(AutoConfigurations.of(LiquibaseAutoConfiguration.class)).withPropertyValues("spring.session.store-type=jdbc", "spring.session.jdbc.initialize-schema=never").run((context) -> {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
String[] sessionRepositoryNames = beanFactory.getBeanNamesForType(JdbcIndexedSessionRepository.class);
assertThat(sessionRepositoryNames).isNotEmpty();
for (String sessionRepositoryName : sessionRepositoryNames) {
assertThat(beanFactory.getBeanDefinition(sessionRepositoryName).getDependsOn()).contains("liquibase");
}
});
}
Aggregations