Spring源码学习--HierarchicalBeanFactory接口

待我称王封你为后i 2022-04-13 05:26 256阅读 0赞

Spring源码学习—HierarchicalBeanFactory接口

2018年06月26日 18:32:39 可乐丶 阅读数:154更多

个人分类: web常见框架学习

所属专栏: Spring使用和源码学习系列

继上一篇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,也是一个二级接口,相对于父接口,它只扩展了一个重要的功能——工厂分层。

  1. /**
  2. * Sub-interface implemented by bean factories that can be part
  3. * of a hierarchy.
  4. *
  5. * <p>The corresponding {@code setParentBeanFactory} method for bean
  6. * factories that allow setting the parent in a configurable
  7. * fashion can be found in the ConfigurableBeanFactory interface.
  8. *
  9. * @author Rod Johnson
  10. * @author Juergen Hoeller
  11. * @since 07.07.2003
  12. * @see org.springframework.beans.factory.config.ConfigurableBeanFactory#setParentBeanFactory
  13. */
  14. public interface HierarchicalBeanFactory extends BeanFactory {
  15. /**
  16. * Return the parent bean factory, or {@code null} if there is none.
  17. */
  18. // // 返回本Bean工厂的父工厂
  19. BeanFactory getParentBeanFactory();
  20. /**
  21. * Return whether the local bean factory contains a bean of the given name,
  22. * ignoring beans defined in ancestor contexts.
  23. * <p>This is an alternative to {@code containsBean}, ignoring a bean
  24. * of the given name from an ancestor bean factory.
  25. * @param name the name of the bean to query
  26. * @return whether a bean with the given name is defined in the local factory
  27. * @see BeanFactory#containsBean
  28. */
  29. // 本地工厂(容器)是否包含这个Bean
  30. boolean containsLocalBean(String name);
  31. }

发表评论

表情:
评论列表 (有 0 条评论,256人围观)

还没有评论,来说两句吧...

相关阅读

    相关 spring学习

    一、先跟着博客一路debug下去。   期间可能会跟丢,但是请反复地debug下去(过程可能很痛苦,但是源码这关是绕不开的),能跟上博客,大致知道做了什么。 要懂得利用