用FactoryBean让Spring配置动起来 - 编程入门网
d to implement
* this method properly, using the current state of the FactoryBean.
* @return the type of object that this FactoryBean creates,
* or <code>null</code> if not known at the time of the call
* @see ListableBeanFactory#getBeansOfType
*/
Class getObjectType();
/**
* Is the bean managed by this factory a singleton or a prototype?
* That is, will <code>getObject()</code> always return the same object
* (a reference that can be cached)?
* <p><b>NOTE:</b> If a FactoryBean indicates to hold a singleton object,
* the object returned from <code>getObject()</code> might get cached
* by the owning BeanFactory. Hence, do not return <code>true</code>
* unless the FactoryBean always exposes the same reference.
* <p>The singleton status of the FactoryBean itself will generally
* be provided by the owning BeanFactory; usually, it has to be
* defined as singleton there.
* @return if this bean is a singleton
* @see #getObject()
*/
boolean isSingleton();
}
用FactoryBean让Spring配置动起来(2)时间:2010-12-31看了以后发现, FactoryBean 用于在 spring 容器中创建其他的 Bean, 我们平时用得最多的 JndiObjectFactoryBean, hibernate 的 LocalSessionFactoryBean 都是 FactoryBean 的具体实现, 既然如此, 读取动态配置就变得易如反掌了, 假如我们要实现动态读取数据库配置的功能, 拿使用率最高的 BasicDatasource 为例, 简单的实现一个 BasicDatasource FactoryBean 如下即可 代码
然后在 spring 中如此声明 代码
就这么简单。 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |