Bean的基本管理
Bean的基本管理
1、BeanFactory、ApplicationContext的关系
ApplicationContext是居于BeanFactory而建立的,也具有读取Bean定义文件,维护Bean之间依赖关系等功能,除此之外,ApplicationContext还提供了一个应用程序所需的更完整的框架功能
2、BeanFactory所拥有的方法
BeanFactory负责读取Bean定义文件:管理对象的加载、生成;维护Bean对象与Bean对象之间的依赖关系;负责Bean的生命周期。对于简单的应用程序来说使用BeanFactory就已经足够来管理Bean了,在对象的管理上已经可以获得很多的方便性,BeanFactory接口包括了6中方法可以调用:
l Boolean containsBean(String):测试BeanFactory中是否包含指定名称的Bean
l Object getBean(String):指定Bean定义文件中设置的名称,可以取得相对应的Bean实例
l Object getBean(String,Class):指定Bean定义文件中设置的名称,取得相对应的Bean的实例,并转换(Cast)指定的类
l Class getType(String name):指定Bean定义文件中设置的名称,取得相对应的Bean的Class实例
l Boolean isSingleton(String):指定Bean定义文件中设置的名称,测试指定的Bean之scope是否为Singleton
String[] getAliases(String):指定Bean定义文件中设置的名称,取得该Bean所有的别名
3、ApplicationContext所扩展的功能
例如:
l 提供更方便地取得资源文件的方法
l 提供解析文字消息的方法
l 支持国际化消息
l ApplicationContext可以发布事件,对事件感兴趣的Bean可以接收这些事件
4、ApplicationContext获取常用的类
l Org.springframework.context.support.FileSystemXmlApplicationContext
可以指定XML定义文件的相对路径或绝对路径读取定义文件
l Org.springframework.context.support.ClassPathXmlApplicationContext
从Classpath设置路径中读取XML定义文件
l Org.springframework.web.context.support.XmlWebApplicationContext
在Web应用程序中的文件架构中,指定相应位置读取定义文件。
ApplicationContext可以读取多个Bean定义文件,可以在实例化ApplicationContext的实现类的时候以数组的方式指定Bean定义文件的位置,例如:
ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{“aaa.xml,bbb.xml”})
5、Bean的实例化
A、使用默认的构造方法,也就是没有参数的构造方法来建立Bean实例
<bean id=”hello” class=”com.itcast.HelloBean”/>
B、通过静态工厂方法来取得某个对象,好处是调用静态工厂方法的对象不用了解对象建立的细节例如:
实例见:http://blog.csdn.net/kongqz/archive/2009/03/14/3990948.aspx
分享到:
相关推荐
spring Framework 2入门经典源代码
《spring framework 2 入门经典》一书的全部源代码
SPring Framework 2入门代码和封面.rar
spring framework 中文参考手册
org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包,org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包org.springframework.flex-1.0.3....
Spring Framework API文档。Spring是什么呢?首先它是一个开源的项目,而且非常活跃;它是一个基于IOC和AOP的构架多层j2ee系统的框架,但它不强迫你必须在每一层中必须使用Spring,因为它模块化的很好,允许你根据...
org.springframework.aop-3.0.4.RELEASE.jar org.springframework.asm-3.0.4.RELEASE.jar org.springframework.aspects-3.0.4.RELEASE.jar org.springframework.beans-3.0.4.RELEASE.jar org.springframework....
Functional programming using lambdas and method references- Stream API- Reactive programming using RxJava 2 and Reactor- Spring WebFlux- Reactive support in Spring Data MongoDB and Spring Security- ...
org\springframework\aop org\springframework\beans org\springframework\cache org\springframework\context org\springframework\core org\springframework\dao org\springframework\ejb org\spring...
Spring Framework 5.1.0源码 The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key ...
Spring Framework 是一个开源的Java/Java EE全功能栈(full-stack)的应用程序框架,以Apache许可证形式发布,也有.NET平台上的移植版本。 该框架基于 Expert One-on-One Java EE Design and Development(ISBN 0-...
Spring Framework 是一个开源的Java/Java EE全功能栈(full-stack)的应用程序框架,以Apache许可证形式发布,也有.NET平台上的移植版本。 该框架基于 Expert One-on-One Java EE Design and Development(ISBN 0-...
Spring Framework 4.x Reference Documentation 中文翻译 Chinese translation of the Spring Framework 4.x Reference Documentation ...
Spring Framework 4.0.2.RELEASE API,该文档来自官网经本人制作而成方便使用的chm格式。
org.springframework.core.jar
This book is an introduction to the well-known Spring Framework that offers an inversion of control container for the Java platform. The Spring Framework is an open source application framework that ...
org.springframework.web.jar,没问题的,最新的。
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
springframework2.5源代码
spring framework 简介