Search in sources :

Example 1 with HierarchicalBeanFactory

use of org.springframework.beans.factory.HierarchicalBeanFactory in project spring-security by spring-projects.

the class UserDetailsServiceFactoryBean method getBeansOfType.

private Map<String, ?> getBeansOfType(Class<?> type) {
    Map<String, ?> beans = beanFactory.getBeansOfType(type);
    // Check ancestor bean factories if they exist and the current one has none of the
    // required type
    BeanFactory parent = beanFactory.getParentBeanFactory();
    while (parent != null && beans.size() == 0) {
        if (parent instanceof ListableBeanFactory) {
            beans = ((ListableBeanFactory) parent).getBeansOfType(type);
        }
        if (parent instanceof HierarchicalBeanFactory) {
            parent = ((HierarchicalBeanFactory) parent).getParentBeanFactory();
        } else {
            break;
        }
    }
    return beans;
}
Also used : HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory)

Example 2 with HierarchicalBeanFactory

use of org.springframework.beans.factory.HierarchicalBeanFactory in project grails-core by grails.

the class ClosureClassIgnoringComponentScanBeanDefinitionParser method createScanner.

@Override
protected ClassPathBeanDefinitionScanner createScanner(XmlReaderContext readerContext, boolean useDefaultFilters) {
    final ClassPathBeanDefinitionScanner scanner = super.createScanner(readerContext, useDefaultFilters);
    BeanDefinitionRegistry beanDefinitionRegistry = readerContext.getRegistry();
    GrailsPluginManager pluginManager = null;
    if (beanDefinitionRegistry instanceof HierarchicalBeanFactory) {
        HierarchicalBeanFactory beanFactory = (HierarchicalBeanFactory) beanDefinitionRegistry;
        BeanFactory parent = beanFactory.getParentBeanFactory();
        if (parent != null && parent.containsBean(GrailsPluginManager.BEAN_NAME)) {
            pluginManager = parent.getBean(GrailsPluginManager.BEAN_NAME, GrailsPluginManager.class);
        }
    }
    if (pluginManager != null) {
        List<TypeFilter> typeFilters = pluginManager.getTypeFilters();
        for (TypeFilter typeFilter : typeFilters) {
            scanner.addIncludeFilter(typeFilter);
        }
    }
    return scanner;
}
Also used : ClassPathBeanDefinitionScanner(org.springframework.context.annotation.ClassPathBeanDefinitionScanner) GrailsPluginManager(grails.plugins.GrailsPluginManager) HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) TypeFilter(org.springframework.core.type.filter.TypeFilter) HierarchicalBeanFactory(org.springframework.beans.factory.HierarchicalBeanFactory)

Aggregations

BeanFactory (org.springframework.beans.factory.BeanFactory)2 HierarchicalBeanFactory (org.springframework.beans.factory.HierarchicalBeanFactory)2 GrailsPluginManager (grails.plugins.GrailsPluginManager)1 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)1 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)1 ClassPathBeanDefinitionScanner (org.springframework.context.annotation.ClassPathBeanDefinitionScanner)1 TypeFilter (org.springframework.core.type.filter.TypeFilter)1