原创作者: bennyparlo
阅读:4407次
评论:0条
更新时间:2011-06-01
在spring的源代码中,有org.springframework.beans.factory.support.BeanDefinitionValueResolver这么个类.
在该类中有private Object resolveReference(String argName, RuntimeBeanReference ref)这样1个方法.
源代码如下:
这个方法的大致作用是,取得bean所依赖的bean实例.但这里遇到问题了.ioc容器在这里做了1个依赖关系的map.但建立了这个依赖关系后,也没有具体使用到他的地方.难以理解设计者的思想.
请各位帮忙解答.谢谢
在该类中有private Object resolveReference(String argName, RuntimeBeanReference ref)这样1个方法.
源代码如下:
private Object resolveReference(String argName, RuntimeBeanReference ref) { if (this.beanFactory.logger.isTraceEnabled()) { this.beanFactory.logger.trace("Resolving reference from property " + argName + " in bean '" + this.beanName + "' to bean '" + ref.getBeanName() + "'"); } try { if (ref.isToParent()) { if (this.beanFactory.getParentBeanFactory() == null) { throw new BeanCreationException( this.beanDefinition.getResourceDescription(), this.beanName, "Can't resolve reference to bean '" + ref.getBeanName() + "' in parent factory: no parent factory available"); } return this.beanFactory.getParentBeanFactory().getBean(ref.getBeanName()); } else { Object bean = this.beanFactory.getBean(ref.getBeanName()); if (this.beanDefinition.isSingleton()) { this.beanFactory.registerDependentBean(ref.getBeanName(), this.beanName); } return bean; } } catch (BeansException ex) { throw new BeanCreationException( this.beanDefinition.getResourceDescription(), this.beanName, "Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex); } }
这个方法的大致作用是,取得bean所依赖的bean实例.但这里遇到问题了.ioc容器在这里做了1个依赖关系的map.但建立了这个依赖关系后,也没有具体使用到他的地方.难以理解设计者的思想.
请各位帮忙解答.谢谢
评论 共 0 条 请登录后发表评论