Example usage for org.springframework.beans.factory ListableBeanFactory getBeanNamesForType

List of usage examples for org.springframework.beans.factory ListableBeanFactory getBeanNamesForType

Introduction

In this page you can find the example usage for org.springframework.beans.factory ListableBeanFactory getBeanNamesForType.

Prototype

String[] getBeanNamesForType(@Nullable Class<?> type, boolean includeNonSingletons, boolean allowEagerInit);

Source Link

Document

Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Usage

From source file:org.lightadmin.core.config.bootstrap.RepositoriesFactoryBean.java

private Map<Class<?>, String> repositoryBeanNames(ListableBeanFactory beanFactory) {
    Map<Class<?>, String> repositoryBeanNames = newHashMap();
    for (String name : beanFactory.getBeanNamesForType(RepositoryFactoryInformation.class, false, false)) {
        RepositoryFactoryInformation repositoryFactoryInformation = beanFactory.getBean(name,
                RepositoryFactoryInformation.class);
        Class<?> userDomainType = ClassUtils
                .getUserClass(repositoryFactoryInformation.getRepositoryInformation().getDomainType());
        repositoryBeanNames.put(userDomainType, BeanFactoryUtils.transformedBeanName(name));
    }//w w  w  . ja  v  a2  s  .  c  o  m
    return repositoryBeanNames;
}

From source file:org.lightadmin.core.config.bootstrap.RepositoriesFactoryBean.java

@SuppressWarnings("unchecked")
private Map<Class<?>, RepositoryFactoryInformation<Object, Serializable>> repositoryFactoryInfos(
        ListableBeanFactory beanFactory) {
    Map<Class<?>, RepositoryFactoryInformation<Object, Serializable>> repositoryFactoryInfos = newHashMap();
    for (String name : beanFactory.getBeanNamesForType(RepositoryFactoryInformation.class, false, false)) {
        RepositoryFactoryInformation repositoryFactoryInformation = beanFactory.getBean(name,
                RepositoryFactoryInformation.class);
        Class<?> userDomainType = ClassUtils
                .getUserClass(repositoryFactoryInformation.getRepositoryInformation().getDomainType());
        repositoryFactoryInfos.put(userDomainType, repositoryFactoryInformation);
    }//ww w  .  j a v  a  2  s .c  o  m
    return repositoryFactoryInfos;
}

From source file:org.springframework.boot.context.embedded.ServletContextInitializerBeans.java

private <T> List<Entry<String, T>> getOrderedBeansOfType(ListableBeanFactory beanFactory, Class<T> type,
        Set<?> excludes) {// w  ww. j a v  a2 s .co m
    List<Entry<String, T>> beans = new ArrayList<Entry<String, T>>();
    Comparator<Entry<String, T>> comparator = new Comparator<Entry<String, T>>() {

        @Override
        public int compare(Entry<String, T> o1, Entry<String, T> o2) {
            return AnnotationAwareOrderComparator.INSTANCE.compare(o1.getValue(), o2.getValue());
        }

    };
    String[] names = beanFactory.getBeanNamesForType(type, true, false);
    Map<String, T> map = new LinkedHashMap<String, T>();
    for (String name : names) {
        if (!excludes.contains(name)) {
            T bean = beanFactory.getBean(name, type);
            if (!excludes.contains(bean)) {
                map.put(name, bean);
            }
        }
    }
    beans.addAll(map.entrySet());
    Collections.sort(beans, comparator);
    return beans;
}

From source file:org.springframework.boot.web.servlet.ServletContextInitializerBeans.java

private <T> List<Entry<String, T>> getOrderedBeansOfType(ListableBeanFactory beanFactory, Class<T> type,
        Set<?> excludes) {// w  ww . j av  a 2  s.c om
    List<Entry<String, T>> beans = new ArrayList<Entry<String, T>>();
    Comparator<Entry<String, T>> comparator = new Comparator<Entry<String, T>>() {

        @Override
        public int compare(Entry<String, T> o1, Entry<String, T> o2) {
            return AnnotationAwareOrderComparator.INSTANCE.compare(o1.getValue(), o2.getValue());
        }

    };
    String[] names = beanFactory.getBeanNamesForType(type, true, false);
    Map<String, T> map = new LinkedHashMap<String, T>();
    for (String name : names) {
        if (!excludes.contains(name) && !ScopedProxyUtils.isScopedTarget(name)) {
            T bean = beanFactory.getBean(name, type);
            if (!excludes.contains(bean)) {
                map.put(name, bean);
            }
        }
    }
    beans.addAll(map.entrySet());
    Collections.sort(beans, comparator);
    return beans;
}