Spring源码学习--HierarchicalBeanFactory接口

继上一篇Spring源码学习–BeanFactory接口

https://blog.csdn.net/u013412772/article/details/80755463

文章引用:

1 https://www.cnblogs.com/leftthen/p/5261837.html
2 https://www.cnblogs.com/zrtqsk/p/4028453.html

这里写图片描述

HierarchicalBeanFactory 提供父容器的访问功能.至于父容器的设置,需要找ConfigurableBeanFactorysetParentBeanFactory(接口把设置跟获取给拆开了!).


HierarchicalBeanFactory源码具体:

  1、第一个方法返回本Bean工厂的父工厂。这个方法实现了工厂的分层。

  2、第二个方法判断本地工厂是否包含这个Bean(忽略其他所有父工厂)。这也是分层思想的体现。

总结:这个工厂接口非常简单,实现了Bean工厂的分层。这个工厂接口也是继承自BeanFacotory,也是一个二级接口,相对于父接口,它只扩展了一个重要的功能——工厂分层。

/**
 * Sub-interface implemented by bean factories that can be part
 * of a hierarchy.
 *
 * <p>The corresponding {@code setParentBeanFactory} method for bean
 * factories that allow setting the parent in a configurable
 * fashion can be found in the ConfigurableBeanFactory interface.
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @since 07.07.2003
 * @see org.springframework.beans.factory.config.ConfigurableBeanFactory#setParentBeanFactory
 */
public interface HierarchicalBeanFactory extends BeanFactory {

    /**
     * Return the parent bean factory, or {@code null} if there is none.
     */
    // //  返回本Bean工厂的父工厂
    BeanFactory getParentBeanFactory();

    /**
     * Return whether the local bean factory contains a bean of the given name,
     * ignoring beans defined in ancestor contexts.
     * <p>This is an alternative to {@code containsBean}, ignoring a bean
     * of the given name from an ancestor bean factory.
     * @param name the name of the bean to query
     * @return whether a bean with the given name is defined in the local factory
     * @see BeanFactory#containsBean
     */
     //  本地工厂(容器)是否包含这个Bean
    boolean containsLocalBean(String name);

}

猜你喜欢

转载自blog.csdn.net/u013412772/article/details/80819269
今日推荐