Search in sources :

Example 11 with ConfigurableListableBeanFactory

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

the class ConditionEvaluationReportTests method parent.

@Test
public void parent() throws Exception {
    this.beanFactory.setParentBeanFactory(new DefaultListableBeanFactory());
    ConditionEvaluationReport.get((ConfigurableListableBeanFactory) this.beanFactory.getParentBeanFactory());
    assertThat(this.report).isSameAs(ConditionEvaluationReport.get(this.beanFactory));
    assertThat(this.report).isNotEqualTo(nullValue());
    assertThat(this.report.getParent()).isNotEqualTo(nullValue());
    ConditionEvaluationReport.get((ConfigurableListableBeanFactory) this.beanFactory.getParentBeanFactory());
    assertThat(this.report).isSameAs(ConditionEvaluationReport.get(this.beanFactory));
    assertThat(this.report.getParent()).isSameAs(ConditionEvaluationReport.get((ConfigurableListableBeanFactory) this.beanFactory.getParentBeanFactory()));
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.Test)

Example 12 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-cloud-connectors by spring-cloud.

the class CloudPropertiesFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    ConfigurableListableBeanFactory listableBeanFactory = (ConfigurableListableBeanFactory) beanFactory;
    if (cloud == null) {
        if (listableBeanFactory.getBeansOfType(CloudFactory.class).isEmpty()) {
            listableBeanFactory.registerSingleton(CLOUD_FACTORY_BEAN_NAME, new CloudFactory());
        }
        CloudFactory cloudFactory = listableBeanFactory.getBeansOfType(CloudFactory.class).values().iterator().next();
        cloud = cloudFactory.getCloud();
    }
}
Also used : CloudFactory(org.springframework.cloud.CloudFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 13 with ConfigurableListableBeanFactory

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

the class OnBeanCondition method getMatchingBeans.

private MatchResult getMatchingBeans(ConditionContext context, BeanSearchSpec beans) {
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    if (beans.getStrategy() == SearchStrategy.ANCESTORS) {
        BeanFactory parent = beanFactory.getParentBeanFactory();
        Assert.isInstanceOf(ConfigurableListableBeanFactory.class, parent, "Unable to use SearchStrategy.PARENTS");
        beanFactory = (ConfigurableListableBeanFactory) parent;
    }
    MatchResult matchResult = new MatchResult();
    boolean considerHierarchy = beans.getStrategy() != SearchStrategy.CURRENT;
    List<String> beansIgnoredByType = getNamesOfBeansIgnoredByType(beans.getIgnoredTypes(), beanFactory, context, considerHierarchy);
    for (String type : beans.getTypes()) {
        Collection<String> typeMatches = getBeanNamesForType(beanFactory, type, context.getClassLoader(), considerHierarchy);
        typeMatches.removeAll(beansIgnoredByType);
        if (typeMatches.isEmpty()) {
            matchResult.recordUnmatchedType(type);
        } else {
            matchResult.recordMatchedType(type, typeMatches);
        }
    }
    for (String annotation : beans.getAnnotations()) {
        List<String> annotationMatches = Arrays.asList(getBeanNamesForAnnotation(beanFactory, annotation, context.getClassLoader(), considerHierarchy));
        annotationMatches.removeAll(beansIgnoredByType);
        if (annotationMatches.isEmpty()) {
            matchResult.recordUnmatchedAnnotation(annotation);
        } else {
            matchResult.recordMatchedAnnotation(annotation, annotationMatches);
        }
    }
    for (String beanName : beans.getNames()) {
        if (!beansIgnoredByType.contains(beanName) && containsBean(beanFactory, beanName, considerHierarchy)) {
            matchResult.recordMatchedName(beanName);
        } else {
            matchResult.recordUnmatchedName(beanName);
        }
    }
    return matchResult;
}
Also used : HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 14 with ConfigurableListableBeanFactory

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

the class ConvertingEncoderDecoderSupport method init.

/**
	 * @see javax.websocket.Encoder#init(EndpointConfig)
	 * @see javax.websocket.Decoder#init(EndpointConfig)
	 */
public void init(EndpointConfig config) {
    ApplicationContext applicationContext = getApplicationContext();
    if (applicationContext != null && applicationContext instanceof ConfigurableApplicationContext) {
        ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
        beanFactory.autowireBean(this);
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 15 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project cas by apereo.

the class ShibbolethAttributeResolverConfiguration method registerBeanIntoApplicationContext.

/**
     * Register bean into application context.
     *
     * @param beanInstance the bean instance
     * @param name         the name
     */
protected void registerBeanIntoApplicationContext(final Object beanInstance, final String name) {
    final Object initBean = this.applicationContext.getAutowireCapableBeanFactory().initializeBean(beanInstance, name);
    final ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
    factory.registerSingleton(name, initBean);
}
Also used : 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