有关spring中的factorybean的深刻理解

Interface to be implemented by objects used within a BeanFactory that are themselves factories. If a bean implements this interface, it is used as a factory, not directly as a bean.

NB: A bean that implements this interface cannot be used as a normal bean. A FactoryBean is defined in a bean style, but the object exposed for bean references is always the object that it creates.

FactoryBeans can support singletons and prototypes, and can either create objects lazily on demand or eagerly on startup.

This interface is heavily used within the framework, for example for the AOP ProxyFactoryBean or JndiObjectFactoryBean. It can be used for application components, but this is not common outside of infrastructure code.


可以自己创建FactoryBean,这个时候的类就要当做工厂类来使用。在spring的配置文件中<ref local="factoryBean"/>调用的是getObject()方法,返回是object对象。


posted on 2007-12-25 15:01 刘铮 阅读(310) 评论(0)  编辑  收藏 所属分类: Spring


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

留言簿(1)

文章分类(141)

文章档案(147)

搜索

最新评论