spring学习4-FactoryBean
来源:互联网 发布:网络十大神曲 编辑:程序博客网 时间:2024/06/15 20:32
Customizing instantiation logic with a FactoryBean
Implement the org.springframework.beans.factory.FactoryBean
interface for objects that are themselves factories.
The FactoryBean
interface is a point of pluggability into the Spring IoC container’s instantiation logic. If you have complex initialization code that is better expressed in Java as opposed to a (potentially) verbose amount of XML, you can create your own FactoryBean
, write the complex initialization inside that class, and then plug your customFactoryBean
into the container.
The FactoryBean
interface provides three methods:
Object getObject()
: returns an instance of the object this factory creates. The instance can possibly be shared, depending on whether this factory returns singletons or prototypes.boolean isSingleton()
: returnstrue
if thisFactoryBean
returns singletons,false
otherwise.Class getObjectType()
: returns the object type returned by thegetObject()
method ornull
if the type is not known in advance.
The FactoryBean
concept and interface is used in a number of places within the Spring Framework; more than 50 implementations of the FactoryBean
interface ship with Spring itself.
When you need to ask a container for an actual FactoryBean
instance itself instead of the bean it produces, preface the bean’s id with the ampersand symbol ( &
) when calling the getBean()
method of the ApplicationContext
. So for a given FactoryBean
with an id of myBean
, invoking getBean("myBean")
on the container returns the product of the FactoryBean
; whereas, invoking getBean("&myBean")
returns the FactoryBean
instance itself.
- spring学习4-FactoryBean
- spring学习之FactoryBean
- spring学习之FactoryBean学习(一)
- spring学习之FactoryBean学习(二)
- Spring FactoryBean
- Spring FactoryBean
- spring FactoryBean
- spring factoryBean
- spring-FactoryBean
- Spring--FactoryBean
- Spring FactoryBean
- Spring学习第十二天:FactoryBean配置bean
- Spring源码学习之BeanFactory和FactoryBean
- 【Spring学习22】容器扩展点:FactoryBean
- Spring源码学习--FactoryBean实现原理
- Spring学习笔记——Spring中的BeanFactory与FactoryBean
- 《Pro Spring》学习笔记之FactoryBean使用(非BeanFactory)
- Spring学习笔记 关于FactoryBean接口的使用
- 折半插入排序
- Eclipse编程之旅:Shell入门(1)
- Oracle数据库中行数的表达rownum
- UVA 10003 - Cutting Sticks
- 设置mysql允许外部IP访问
- spring学习4-FactoryBean
- Cocos开发中性能优化工具介绍之Xcode中Instruments工具使用
- 创建win32 dll
- 程序人生的四个象限和两条主线----值得一看的职业规划
- “以图搜图”引擎及网站合集(转)
- (七)OSAL系统框架
- Linux下QoS模块之tc(traffic control)操作简介
- MARK一下:VC各种文件格式
- oracle 数据的导入 导出