Spring容器,最基本的接口就是BeanFactory 负责创建,配置,管理bean 它有一个子接口ApplicationContext并将功能扩展。
        理论上bean装配可以从任何资源获得,包括属性文件,关系数据库等,但xml是最常用的XmlBeanFactory,ClassPathXmlApplicationContext,FileSystemXmlApplicationContext,XmlWebApplicationContext应用系统配置源。Spring中的几种容器都支持使用xml装配bean,包括:
        XmlBeanFactory,ClassPathXmlApplicationContext,FileSystemXmlApplicationContext,XmlWebApplicationContext
        BeanFactory接口包含如下的基本方法:
Boolean containsBean(String name):判断Spring容器是否包含id为name的bean定义。
Object getBean(String name):返回容器id为name的bean。
Object getBean(String name, Class requiredType):返回容器中id为name,并且类型为requiredType的bean。
Class getType(String name):返回容器中id为name的bean的类型。
        ApplicationContext有三个实现类实现资源访问:
FileSystemXmlApplicationContext:基于文件系统的xml配置文件创建ApplicationContext。
ClassPathXmlApplicationContext:以类加载路径下的xml的配置文件创建ApplicationContext(更为常用)。
XmlWebApplicationContext:对使用servletContextResource进行资源访问。
        获得容器的应用的方式:
① InputStream is = new FileInputStream("bean.xml");
XmlBeanFactory factory = new XmlBeanFactory(is);
或者BeanFactory factory = new XmlBeanFactory(new ClassPathResource("classpath:bean.xml"))
Action action = (Action) factory.getBean("TheAction");
② ApplicationContext bf=new ClassPathXmlApplicationContext("classpath:bean.xml")
Action action = (Action) factory.getBean("TheAction");
③ ApplicationContext bf=new FileSystemXmlApplicationContext(“classpath:bean.xml”)
        第一种BeanFactory启动快(启动是不创建实体,到用时才创建实体),

第二种ApplicationContext运行快(在加载时就创建好实体)更为常用,继承BeanFactory。

BeanFactory的更多相关文章

  1. Spring之BeanFactory及Bean生命周期

    1.spring通过BeanFactory灵活配置.管理bean,Spring对管理的bean没有任何特别的要求,完全支持对POJO的管理: 2.BeanFactory有个ApplicationCon ...

  2. [spring源码学习]六、IOC源码-BeanFactory和factory-bean

    一.代码实例 在我们分析spring的IOC源码的时候,发现除了配置标准的bean,并且通过getBean(beanName)的方法获取到一个bean的实例外,似乎还有这不少其他获取的方法,例如在第四 ...

  3. Bean生命周期及BeanFactory

    1.spring通过BeanFactory灵活配置.管理bean,Spring对管理的bean没有任何特别的要求,完全支持对POJO的管理: 2.BeanFactory有个ApplicationCon ...

  4. Spring源码分析——BeanFactory体系之抽象类、类分析(二)

    上一篇分析了BeanFactory体系的2个类,SimpleAliasRegistry和DefaultSingletonBeanRegistry——Spring源码分析——BeanFactory体系之 ...

  5. Spring源码分析——BeanFactory体系之抽象类、类分析(一)

    上一篇介绍了BeanFactory体系的所有接口——Spring源码分析——BeanFactory体系之接口详细分析,本篇就接着介绍BeanFactory体系的抽象类和接口. 一.BeanFactor ...

  6. Spring源码分析——BeanFactory体系之接口详细分析

    Spring的BeanFactory的继承体系堪称经典.这是众所周知的!作为Java程序员,不能错过! 前面的博文分析了Spring的Resource资源类Resouce.今天开始分析Spring的I ...

  7. Spring-IOC-BeanFactory

    BeanFactory BeanFactory 是 Spring 的“心脏”.它就是 Spring IoC 容器的真面目.Spring 使用 BeanFactory 来实例化.配置和管理 Bean.但 ...

  8. spring之BeanFactory

    spring的IOC容器能够帮我们自动new对象,对象交给spring管之后我们不用自己手动去new对象了.那么它的原理是什么呢?是怎么实现的呢?下面我来简单的模拟一下spring的机制,相信看完之后 ...

  9. Spring系列之beanFactory与ApplicationContext

    一.BeanFactoryBeanFactory 是 Spring 的“心脏”.它就是 Spring IoC 容器的真面目.Spring 使用 BeanFactory 来实例化.配置和管理 Bean. ...

  10. BeanFactory和ApplicationContext的区别

     1.BeanFactory和ApplicationContext的异同点: 相同点:     两者都是通过xml配置文件加载bean,ApplicationContext和BeanFacotry相比 ...

随机推荐

  1. nRF51822之pstorage使用摘要

    https://devzone.nordicsemi.com/question/15271/how-can-i-write-10kb-of-data-to-internal-flash/?answer ...

  2. Tinyxml的简单应用

    参考文章: 1-> http://www.cnblogs.com/phinecos/archive/2008/03/11/1100912.html 2-> http://blog.csdn ...

  3. 20145211 《Java程序设计》第10周学习总结——昨夜星辰昨夜风

    教材学习内容总结 网络编程 网络编程就是在两个或两个以上的设备(例如计算机)之间传输数据. 程序员所作的事情就是把数据发送到指定的位置,或者接收到指定的数据,这个就是狭义的网络编程范畴. 在发送和接收 ...

  4. [LeetCode] Letter Combinations of a Phone Number(bfs)

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  5. android 打开软件出现红框

    android打开软件的时候会出现红框,剑锋之前解了这个问题.fork过来,方便以后查看. 参考链接: http://www.cnblogs.com/zengjfgit/p/5377744.html ...

  6. LeetCode Word Break II

    原题链接在这里:https://leetcode.com/problems/word-break-ii/ 题目: Given a string s and a dictionary of words  ...

  7. 与Perl兼容的正则表达式函数

    <?php $str = "abc_ABC_123abc"; $patt = '/^abc(.*?)abc$/'; //有一个模式单元就会多一个存储 $arr = null; ...

  8. 复合事件ready,hover,toggle

    1.ready 2.hover 3.toggle(fn1,fn2, …)(被废弃) 2.hover(fn(){……},fn(){……}) 特别强调一点,hover的是mouseenter和mousel ...

  9. Python开发【第二章】:Python的数据类型

    基本数据类型 一.整型 如: 18.73.84 整型具备如下功能: class int(object): """ int(x=0) -> int or long i ...

  10. [BS-14] 打印NSArray和NSDictionary的3种方法

    打印NSArray和NSDictionary的3种方法 NSArray *arr = @[@"奔驰",@"宝马",@"路虎",@" ...