/** * Check the BeanFactory to see whether the bean named <var>beanName</var> already * exists. Accounts for the fact that the requested bean may be "in creation", i.e.: * we're in the middle of servicing the initial request for this bean. From an enhanced * factory method's perspective, this means that the bean does not actually yet exist, * and that it is now our job to create it for the first time by executing the logic * in the corresponding factory method. * <p>Said another way, this check repurposes * {@link ConfigurableBeanFactory#isCurrentlyInCreation(String)} to determine whether * the container is calling this method or the user is calling this method. * @param beanName name of bean to check for * @return whether <var>beanName</var> already exists in the factory */ private boolean factoryContainsBean(ConfigurableBeanFactory beanFactory, String beanName) { return (beanFactory.containsBean(beanName) && !beanFactory.isCurrentlyInCreation(beanName)); }
/** * Resolves the specified interceptor names to Advisor objects. * @see #setInterceptorNames */ private Advisor[] resolveInterceptorNames() { BeanFactory bf = this.beanFactory; ConfigurableBeanFactory cbf = (bf instanceof ConfigurableBeanFactory ? (ConfigurableBeanFactory) bf : null); List<Advisor> advisors = new ArrayList<>(); for (String beanName : this.interceptorNames) { if (cbf == null || !cbf.isCurrentlyInCreation(beanName)) { Assert.state(bf != null, "BeanFactory required for resolving interceptor names"); Object next = bf.getBean(beanName); advisors.add(this.advisorAdapterRegistry.wrap(next)); } } return advisors.toArray(new Advisor[0]); }
@Override @Nullable public Object getObject() throws BeansException { BeanWrapper target = this.targetBeanWrapper; if (target != null) { if (logger.isWarnEnabled() && this.targetBeanName != null && this.beanFactory instanceof ConfigurableBeanFactory && ((ConfigurableBeanFactory) this.beanFactory).isCurrentlyInCreation(this.targetBeanName)) { logger.warn("Target bean '" + this.targetBeanName + "' is still in creation due to a circular " + "reference - obtained value for property '" + this.propertyPath + "' may be outdated!"); } } else { // Fetch prototype target bean... Assert.state(this.beanFactory != null, "No BeanFactory available"); Assert.state(this.targetBeanName != null, "No target bean name specified"); Object bean = this.beanFactory.getBean(this.targetBeanName); target = PropertyAccessorFactory.forBeanPropertyAccess(bean); } Assert.state(this.propertyPath != null, "No property path specified"); return target.getPropertyValue(this.propertyPath); }
/** * Check the BeanFactory to see whether the bean named <var>beanName</var> already * exists. Accounts for the fact that the requested bean may be "in creation", i.e.: * we're in the middle of servicing the initial request for this bean. From an enhanced * factory method's perspective, this means that the bean does not actually yet exist, * and that it is now our job to create it for the first time by executing the logic * in the corresponding factory method. * <p>Said another way, this check repurposes * {@link ConfigurableBeanFactory#isCurrentlyInCreation(String)} to determine whether * the container is calling this method or the user is calling this method. * @param beanName name of bean to check for * @return whether <var>beanName</var> already exists in the factory */ private boolean factoryContainsBean(ConfigurableBeanFactory beanFactory, String beanName) { return (beanFactory.containsBean(beanName) && !beanFactory.isCurrentlyInCreation(beanName)); }
@Override @Nullable public Object getObject() throws BeansException { BeanWrapper target = this.targetBeanWrapper; if (target != null) { if (logger.isWarnEnabled() && this.targetBeanName != null && this.beanFactory instanceof ConfigurableBeanFactory && ((ConfigurableBeanFactory) this.beanFactory).isCurrentlyInCreation(this.targetBeanName)) { logger.warn("Target bean '" + this.targetBeanName + "' is still in creation due to a circular " + "reference - obtained value for property '" + this.propertyPath + "' may be outdated!"); } } else { // Fetch prototype target bean... Assert.state(this.beanFactory != null, "No BeanFactory available"); Assert.state(this.targetBeanName != null, "No target bean name specified"); Object bean = this.beanFactory.getBean(this.targetBeanName); target = PropertyAccessorFactory.forBeanPropertyAccess(bean); } Assert.state(this.propertyPath != null, "No property path specified"); return target.getPropertyValue(this.propertyPath); }
String msg = "Factory method '" + factoryMethod.getName() + "' threw exception"; if (bd.getFactoryBeanName() != null && owner instanceof ConfigurableBeanFactory && ((ConfigurableBeanFactory) owner).isCurrentlyInCreation(bd.getFactoryBeanName())) { msg = "Circular reference involving containing bean '" + bd.getFactoryBeanName() + "' - consider " + "declaring the factory method as static for independence from its containing instance. " + msg;
boolean alreadyInCreation = beanFactory.isCurrentlyInCreation(beanName); try { if (alreadyInCreation) {
if (beanFactory.isCurrentlyInCreation(scopedBeanName)) { beanName = scopedBeanName;
boolean alreadyInCreation = beanFactory.isCurrentlyInCreation(beanName); try { if (alreadyInCreation) {
String msg = "Factory method '" + factoryMethod.getName() + "' threw exception"; if (bd.getFactoryBeanName() != null && owner instanceof ConfigurableBeanFactory && ((ConfigurableBeanFactory) owner).isCurrentlyInCreation(bd.getFactoryBeanName())) { msg = "Circular reference involving containing bean '" + bd.getFactoryBeanName() + "' - consider " + "declaring the factory method as static for independence from its containing instance. " + msg;
if (beanFactory.isCurrentlyInCreation(scopedBeanName)) { beanName = scopedBeanName;
public Object getObject() throws BeansException { BeanWrapper target = this.targetBeanWrapper; if (target != null) { if (logger.isWarnEnabled() && this.targetBeanName != null && this.beanFactory instanceof ConfigurableBeanFactory && ((ConfigurableBeanFactory) this.beanFactory).isCurrentlyInCreation(this.targetBeanName)) { logger.warn("Target bean '" + this.targetBeanName + "' is still in creation due to a circular " + "reference - obtained value for property '" + this.propertyPath + "' may be outdated!"); } } else { // Fetch prototype target bean... Object bean = this.beanFactory.getBean(this.targetBeanName); target = PropertyAccessorFactory.forBeanPropertyAccess(bean); } return target.getPropertyValue(this.propertyPath); }
/** * Resolves the specified interceptor names to Advisor objects. * @see #setInterceptorNames */ private Advisor[] resolveInterceptorNames() { ConfigurableBeanFactory cbf = (this.beanFactory instanceof ConfigurableBeanFactory ? (ConfigurableBeanFactory) this.beanFactory : null); List<Advisor> advisors = new ArrayList<Advisor>(); for (String beanName : this.interceptorNames) { if (cbf == null || !cbf.isCurrentlyInCreation(beanName)) { Object next = this.beanFactory.getBean(beanName); advisors.add(this.advisorAdapterRegistry.wrap(next)); } } return advisors.toArray(new Advisor[advisors.size()]); }
/** * Check the BeanFactory to see whether the bean named <var>beanName</var> already * exists. Accounts for the fact that the requested bean may be "in creation", i.e.: * we're in the middle of servicing the initial request for this bean. From an enhanced * factory method's perspective, this means that the bean does not actually yet exist, * and that it is now our job to create it for the first time by executing the logic * in the corresponding factory method. * <p>Said another way, this check repurposes * {@link ConfigurableBeanFactory#isCurrentlyInCreation(String)} to determine whether * the container is calling this method or the user is calling this method. * @param beanName name of bean to check for * @return whether <var>beanName</var> already exists in the factory */ private boolean factoryContainsBean(ConfigurableBeanFactory beanFactory, String beanName) { return (beanFactory.containsBean(beanName) && !beanFactory.isCurrentlyInCreation(beanName)); }
/** * Resolves the specified interceptor names to Advisor objects. * @see #setInterceptorNames */ private Advisor[] resolveInterceptorNames() { BeanFactory bf = this.beanFactory; ConfigurableBeanFactory cbf = (bf instanceof ConfigurableBeanFactory ? (ConfigurableBeanFactory) bf : null); List<Advisor> advisors = new ArrayList<>(); for (String beanName : this.interceptorNames) { if (cbf == null || !cbf.isCurrentlyInCreation(beanName)) { Assert.state(bf != null, "BeanFactory required for resolving interceptor names"); Object next = bf.getBean(beanName); advisors.add(this.advisorAdapterRegistry.wrap(next)); } } return advisors.toArray(new Advisor[0]); }
@Override public Object getObject() throws BeansException { BeanWrapper target = this.targetBeanWrapper; if (target != null) { if (logger.isWarnEnabled() && this.targetBeanName != null && this.beanFactory instanceof ConfigurableBeanFactory && ((ConfigurableBeanFactory) this.beanFactory).isCurrentlyInCreation(this.targetBeanName)) { logger.warn("Target bean '" + this.targetBeanName + "' is still in creation due to a circular " + "reference - obtained value for property '" + this.propertyPath + "' may be outdated!"); } } else { // Fetch prototype target bean... Object bean = this.beanFactory.getBean(this.targetBeanName); target = PropertyAccessorFactory.forBeanPropertyAccess(bean); } return target.getPropertyValue(this.propertyPath); }
String msg = "Factory method '" + factoryMethod.getName() + "' threw exception"; if (bd.getFactoryBeanName() != null && owner instanceof ConfigurableBeanFactory && ((ConfigurableBeanFactory) owner).isCurrentlyInCreation(bd.getFactoryBeanName())) { msg = "Circular reference involving containing bean '" + bd.getFactoryBeanName() + "' - consider " + "declaring the factory method as static for independence from its containing instance. " + msg;
boolean alreadyInCreation = beanFactory.isCurrentlyInCreation(beanName); try { if (alreadyInCreation) {
if (beanFactory.isCurrentlyInCreation(scopedBeanName)) { beanName = scopedBeanName;