浏览 3536 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-02-23
“This may be done by prepending the bean id with & when calling the getBean method of BeanFactory(including ApplicationContext). So for a given FactoryBean with an id myBean, invoking getBean("myBean")on the BeanFactory will return the product of the FactoryBean, but invoking getBean("&myBean") will returnthe FactoryBean instance itself” 这句话表明了事情的原委,如果是factorybean的话,他会取得他的方法的产品,所以诸如的是HibernateDaoSupport的产品,就是getSessionFactory的返回值。一个细小的地方,造成误会。 spring处理此处的地方代码如下,可以解释spring如何进行的数据处理 //仔细察看spring的注释 // Now we have the bean instance, which may be a normal bean or a FactoryBean. // If it's a FactoryBean, we use it to create a bean instance, unless the // caller actually wants a reference to the factory. if (beanInstance instanceof FactoryBean) { if (!isFactoryDereference(name)) { // Return bean instance from factory. FactoryBean factory = (FactoryBean) beanInstance; if (logger.isDebugEnabled()) { logger.debug("Bean with name '" + beanName + "' is a factory bean"); } try { beanInstance = factory.getObject(); } catch (Exception ex) { throw new BeanCreationException(beanName, "FactoryBean threw exception on object creation", ex); } if (beanInstance == null) { throw new FactoryBeanNotInitializedException( beanName, "FactoryBean returned null object: " + "probably not fully initialized (maybe due to circular bean reference)"); } } else { // The user wants the factory itself. if (logger.isDebugEnabled()) { logger.debug("Calling code asked for FactoryBean instance for name '" + beanName + "'"); } } }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-02-23
如果该 id所引用的bean是FactoryBean实例,则检查是否使用了&,
如果没有则调用FactoryBean的getObject方法来取得产品。 |
|
返回顶楼 | |