zoukankan      html  css  js  c++  java
  • Spring源码入门——XmlBeanFactory源码学习

    XmlBeanFactory虽然在Spring 3.1之后标记为@Deprecated,具体用法改为

    1         XmlBeanFactory factory = new XmlBeanFactory( new ClassPathResource("knights.xml"));
    2         //替换为
    3         DefaultListableBeanFactory fac = new DefaultListableBeanFactory();
    4         BeanDefinitionReader reader = new XmlBeanDefinitionReader(fac);
    5         reader.loadBeanDefinitions( new ClassPathResource("knights.xml"));

    而我们通过XmlBeanFactory的实例化方式可以看到新的写法只是把原来的实例化流程拿出来了而已。而Spring的Jira中写到了这么一段

        private final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this);
    
        public XmlBeanFactory(Resource resource) throws BeansException {
            this(resource, null);
        }
    
        
        public XmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException {
            super(parentBeanFactory);
            this.reader.loadBeanDefinitions(resource);
        }    

     而Spring的Jira中写到了这么一段话:

      XmlBeanFactory was deprecated because it existed before the ApplicationContext abstraction did, and theApplicationContext hierarchy was specifically designed to accommodate concrete types aligned with different bean definition types (GenericXmlApplicationContextAnnotationConfigApplicationContext, etc), while the BeanFactory hierarchy represents a more fundamental abstraction not designed for such variability. XmlBeanFactory is the one historical exception to that rule, and the deprecation reflects that fact. Given that GenericXmlApplicationContext provides equal if not greater convenience (given the String- and Resource-based constructors), undeprecating is unlikely at this point.

      先从XmlBeanFactory的继承体系开始(不完整):  概念上来讲,

    •   BeanFactory,定义获取bean及bean的各种属性
    •   BeanDefinitionRegistry,定义对BeanDefinition的各种增删改查操作。
    •   BeanDefinitionReader,定义从资源文件加载为BeanDefinition的流程

      这样我们可以把XmlBeanFactory加载bean的操作分为两个部分,1,读取文件解析为BeanDefinition集合注册给registry(参考:http://www.cnblogs.com/jason0529/p/5239139.html );2,读取BeanDefinition并转换为bean实例返回。第一个流程就是BeaDefinitionReader这个接口定义完成的事情,第二步是BeanFactory需要完成的工作。

      

            

  • 相关阅读:
    Jetty开发指导:WebSocket介绍
    Python处理JSON
    聚焦数据可视化之中的一个--沃尔马怎样利用数据可视化依据实时社交数据调整採购和仓储计划?
    刚刚在寻找微博
    2010级信管毕业生实习总结汇编版(共29份)
    推荐杀毒软件
    Windows Server 2008 R2 下载地址
    在myeclipse中使用log4j记录日志
    获取Tomcat更详细的日志
    java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
  • 原文地址:https://www.cnblogs.com/jason0529/p/5227560.html
Copyright © 2011-2022 走看看