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. C#中Attribute介绍

    什么是特性? MSDN中定义为:公共语言运行时运行添加类似关键字的描述声明,叫做Attribute,它对程序中的元素进行标注,如类型.方法.字段和属性等.attribute和Microsoft.Net ...

  2. 【android学习4】Eclipse中Clean作用

    今天修改Servlet中代码,重启服务端程序之后发现没有启作用,于是Clean了一把,果然生效. 查阅资料得知,Eclipse中是根据时间戳去编译代码,如果某个类对应的时间戳没有发生改变就不会重新编译 ...

  3. [LeetCode] Combination Sum (bfs)

    Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C wher ...

  4. PHP运行错最有效解决办法Fatal error: Out of memory (allocated 786432) (tried to allocate 98304 bytes) in H:\freehost\zhengbao2\web\includes\lib_common.php on line 744

    原文 PHP运行错最有效解决办法Fatal error: Out of memory (allocated 6029312) Fatal error: Out of memory (allocated ...

  5. (leetcode) countandsay

    class Solution { public: string calcuate(string s) { string result; char pre = s[0]; int cnt = 1; fo ...

  6. Sort---hdu5884(优先队列+二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 题意:有n个有序序列,每个序列有ai个元素,现在有一个程序每次可以归并最多k个序列,最终把所有的 ...

  7. 控制台打印出event对象时,对象里面的currentTarget为null

    但是MouseEvent对象展开时 附上老外的解释~~~: http://stackoverflow.com/questions/26496176/when-loggin-an-event-objec ...

  8. MVC中@Html.DisPlayFor(model=>model.newsName)和 @Model.newsName的区别

    MVC中,在Controllers查询到数据,返回一个实体给View并显示,可以用@Html.DisPlayFor(model=>model.newsName)和 @Model.newsName ...

  9. 如何在intellj Idea中给新建的项目添加jar包?

    1. 假如我加入joda.jar 2. 找到发布的你想要的jar包,下载! 3. 解压刚下载的jar包,复制 4. 在intellj idea中新建一个java项目,然后创建一个专门用于放jar的li ...

  10. iOS腾讯百度面试题