Search in sources :

Example 1 with AbstractAutowireCapableBeanFactory

use of org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 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;
    }
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AbstractAutowireCapableBeanFactory(org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 2 with AbstractAutowireCapableBeanFactory

use of org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory 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);
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) AbstractAutowireCapableBeanFactory(org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 3 with AbstractAutowireCapableBeanFactory

use of org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory in project pf4j-spring by pf4j.

the class SpringPluginManager method init.

/**
 * This method load, start plugins and inject extensions in Spring
 */
@PostConstruct
public void init() {
    loadPlugins();
    startPlugins();
    AbstractAutowireCapableBeanFactory beanFactory = (AbstractAutowireCapableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
    ExtensionsInjector extensionsInjector = new ExtensionsInjector(this, beanFactory);
    extensionsInjector.injectExtensions();
}
Also used : AbstractAutowireCapableBeanFactory(org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory) PostConstruct(javax.annotation.PostConstruct)

Example 4 with AbstractAutowireCapableBeanFactory

use of org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory in project spring-boot by spring-projects.

the class BeanCurrentlyInCreationFailureAnalyzerTests method createFailure.

private Exception createFailure(Class<?> configuration, boolean allowCircularReferences) {
    try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
        context.register(configuration);
        AbstractAutowireCapableBeanFactory beanFactory = (AbstractAutowireCapableBeanFactory) context.getBeanFactory();
        this.analyzer.setBeanFactory(beanFactory);
        beanFactory.setAllowCircularReferences(allowCircularReferences);
        context.refresh();
        fail("Expected failure did not occur");
        return null;
    } catch (Exception ex) {
        return ex;
    }
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AbstractAutowireCapableBeanFactory(org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory) IOException(java.io.IOException) BeanCurrentlyInCreationException(org.springframework.beans.factory.BeanCurrentlyInCreationException)

Aggregations

AbstractAutowireCapableBeanFactory (org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory)4 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)2 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)2 IOException (java.io.IOException)1 PostConstruct (javax.annotation.PostConstruct)1 BeanCurrentlyInCreationException (org.springframework.beans.factory.BeanCurrentlyInCreationException)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1