您的位置:首页 >> 编程开发 >> Java >> JavaBeans >> 正文
RSS
 

BeanFactory & Context In Spring

http://www.rdxx.com 05年07月27日 22:48 CSDN 我要投稿

关键词: Spring , Factory , Bean , NT , BEA , CTO

1. org.springframework.beans.factory包

构建了sping IOC的基础, 支持IOC类型2(get/set) 和类型3(构造函数)

bean的生命周期: 配置定义-初始化(init-method)-被beanfactory装载--析构(destroy-method)

<ref bean=A/>引用:

bean:同时尝试在当前XML文件或其他XML文件中查找指定的合作者bean

local:仅在当前XML文件中查找合作者。这个attribute是一个XML IDREF,所以它必须存在,否则校验会失败。

external:显式指定在其他XML文件中查找合作者而不搜索当前XML文件。在这样一组情况下,这是可能的:指定一些更复杂的属性,如lists, properties object 和maps。

 

在XML文件中指定属性及合作者你必须使用嵌套的<property>元素

1) list

<property name="someList">

<list>

<value>a list element followed by a reference</value>

<ref bean="myDataSource"/>

</list>

            </property>

2)Map

<property name="someMap">

<map>

<entry key="yup an entry">

<value>just some string</value>

</entry>

<entry key="yup a ref">

<ref bean="myDataSource</ref>

</entry>

</map>

</property>

3)properties

 

<property name="people">

<props>

<prop key="HaaryPotter">The magic property</prop>

<prop key="JerrySeinfeld">The funny property</prop>

</props>

</property>

2. org.springframework.context.ApplicationContext接口

context包位于beans包之上,提供了管理和操作bean的一般能力。ApplicationContext包括了bean factory的所有功能.



 
 
标签: Spring , Factory , Bean , NT , BEA , CTO 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站