Search in sources :

Example 6 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-framework by spring-projects.

the class AbstractApplicationContext method initApplicationEventMulticaster.

/**
	 * Initialize the ApplicationEventMulticaster.
	 * Uses SimpleApplicationEventMulticaster if none defined in the context.
	 * @see org.springframework.context.event.SimpleApplicationEventMulticaster
	 */
protected void initApplicationEventMulticaster() {
    ConfigurableListableBeanFactory beanFactory = getBeanFactory();
    if (beanFactory.containsLocalBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME)) {
        this.applicationEventMulticaster = beanFactory.getBean(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, ApplicationEventMulticaster.class);
        if (logger.isDebugEnabled()) {
            logger.debug("Using ApplicationEventMulticaster [" + this.applicationEventMulticaster + "]");
        }
    } else {
        this.applicationEventMulticaster = new SimpleApplicationEventMulticaster(beanFactory);
        beanFactory.registerSingleton(APPLICATION_EVENT_MULTICASTER_BEAN_NAME, this.applicationEventMulticaster);
        if (logger.isDebugEnabled()) {
            logger.debug("Unable to locate ApplicationEventMulticaster with name '" + APPLICATION_EVENT_MULTICASTER_BEAN_NAME + "': using default [" + this.applicationEventMulticaster + "]");
        }
    }
}
Also used : SimpleApplicationEventMulticaster(org.springframework.context.event.SimpleApplicationEventMulticaster) ApplicationEventMulticaster(org.springframework.context.event.ApplicationEventMulticaster) SimpleApplicationEventMulticaster(org.springframework.context.event.SimpleApplicationEventMulticaster) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 7 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-framework by spring-projects.

the class AbstractApplicationContext method obtainFreshBeanFactory.

/**
	 * Tell the subclass to refresh the internal bean factory.
	 * @return the fresh BeanFactory instance
	 * @see #refreshBeanFactory()
	 * @see #getBeanFactory()
	 */
protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
    refreshBeanFactory();
    ConfigurableListableBeanFactory beanFactory = getBeanFactory();
    if (logger.isDebugEnabled()) {
        logger.debug("Bean factory for " + getDisplayName() + ": " + beanFactory);
    }
    return beanFactory;
}
Also used : ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 8 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-framework by spring-projects.

the class AbstractApplicationContext method refresh.

@Override
public void refresh() throws BeansException, IllegalStateException {
    synchronized (this.startupShutdownMonitor) {
        // Prepare this context for refreshing.
        prepareRefresh();
        // Tell the subclass to refresh the internal bean factory.
        ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
        // Prepare the bean factory for use in this context.
        prepareBeanFactory(beanFactory);
        try {
            // Allows post-processing of the bean factory in context subclasses.
            postProcessBeanFactory(beanFactory);
            // Invoke factory processors registered as beans in the context.
            invokeBeanFactoryPostProcessors(beanFactory);
            // Register bean processors that intercept bean creation.
            registerBeanPostProcessors(beanFactory);
            // Initialize message source for this context.
            initMessageSource();
            // Initialize event multicaster for this context.
            initApplicationEventMulticaster();
            // Initialize other special beans in specific context subclasses.
            onRefresh();
            // Check for listener beans and register them.
            registerListeners();
            // Instantiate all remaining (non-lazy-init) singletons.
            finishBeanFactoryInitialization(beanFactory);
            // Last step: publish corresponding event.
            finishRefresh();
        } catch (BeansException ex) {
            if (logger.isWarnEnabled()) {
                logger.warn("Exception encountered during context initialization - " + "cancelling refresh attempt: " + ex);
            }
            // Destroy already created singletons to avoid dangling resources.
            destroyBeans();
            // Reset 'active' flag.
            cancelRefresh(ex);
            // Propagate exception to caller.
            throw ex;
        } finally {
            // Reset common introspection caches in Spring's core, since we
            // might not ever need metadata for singleton beans anymore...
            resetCommonCaches();
        }
    }
}
Also used : ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) BeansException(org.springframework.beans.BeansException)

Example 9 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class PropertyMappingContextCustomizerFactoryTests method getContextCustomizerWhenHasNoMappingShouldNotAddPropertySource.

@Test
public void getContextCustomizerWhenHasNoMappingShouldNotAddPropertySource() {
    ContextCustomizer customizer = this.factory.createContextCustomizer(NoMapping.class, null);
    ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
    ConfigurableEnvironment environment = mock(ConfigurableEnvironment.class);
    ConfigurableListableBeanFactory beanFactory = mock(ConfigurableListableBeanFactory.class);
    given(context.getEnvironment()).willReturn(environment);
    given(context.getBeanFactory()).willReturn(beanFactory);
    customizer.customizeContext(context, null);
    verifyZeroInteractions(environment);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ContextCustomizer(org.springframework.test.context.ContextCustomizer) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.Test)

Example 10 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfiguration method registerServletWebServerFactory.

private void registerServletWebServerFactory(AnnotationConfigServletWebServerApplicationContext childContext) {
    try {
        ConfigurableListableBeanFactory beanFactory = childContext.getBeanFactory();
        if (beanFactory instanceof BeanDefinitionRegistry) {
            BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
            registry.registerBeanDefinition("ServletWebServerFactory", new RootBeanDefinition(determineServletWebServerFactoryClass()));
        }
    } catch (NoSuchBeanDefinitionException ex) {
    // Ignore and assume auto-configuration
    }
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Aggregations

ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)32 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)5 BeanFactoryPostProcessor (org.springframework.beans.factory.config.BeanFactoryPostProcessor)4 ApplicationContext (org.springframework.context.ApplicationContext)4 Test (org.junit.Test)3 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)3 CloudFactory (org.springframework.cloud.CloudFactory)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 BeansException (org.springframework.beans.BeansException)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)2 GrailsPlugin (grails.plugins.GrailsPlugin)1 ConfigObject (groovy.util.ConfigObject)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 EntityManagerFactory (javax.persistence.EntityManagerFactory)1 ServletContext (javax.servlet.ServletContext)1 MultifactorAuthenticationProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProperties)1 NavigableMap (org.grails.config.NavigableMap)1