BeanFactoryUtils.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:gemini.blueprint 作者:
/**
 * Return all beans depending directly or indirectly (transitively), on the bean identified by the beanName. When
 * dealing with a FactoryBean, the factory itself can be returned or its product. Additional filtering can be
 * executed through the type parameter. If no filtering is required, then null can be passed.
 * 
 * Note that depending on #rawFactoryBeans parameter, the type of the factory or its product can be used when doing
 * the filtering.
 * 
 * @param beanFactory beans bean factory
 * @param beanName root bean name
 * @param rawFactoryBeans consider the factory bean itself or the its product
 * @param type type of the beans returned (null to return all beans)
 * @return bean names
 */
public static String[] getTransitiveDependenciesForBean(ConfigurableListableBeanFactory beanFactory,
        String beanName, boolean rawFactoryBeans, Class<?> type) {
    Assert.notNull(beanFactory);
    Assert.hasText(beanName);

    Assert.isTrue(beanFactory.containsBean(beanName), "no bean by name [" + beanName + "] can be found");

    Set<String> beans = new LinkedHashSet<String>(8);
    // used to break cycles between nested beans
    Set<String> innerBeans = new LinkedHashSet<String>(4);

    getTransitiveBeans(beanFactory, beanName, rawFactoryBeans, beans, innerBeans);

    if (type != null) {
        // filter by type
        for (Iterator<String> iter = beans.iterator(); iter.hasNext();) {
            String bean = iter.next();
            if (!beanFactory.isTypeMatch(bean, type)) {
                iter.remove();
            }
        }
    }

    return beans.toArray(new String[beans.size()]);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号