|
|
|
@ -991,54 +991,60 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, RootBeanDefinition mbd) { |
|
|
|
private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, RootBeanDefinition mbd) { |
|
|
|
BeanWrapper bw = this.factoryBeanInstanceCache.get(beanName); |
|
|
|
this.singletonLock.lock(); |
|
|
|
if (bw != null) { |
|
|
|
|
|
|
|
return (FactoryBean<?>) bw.getWrappedInstance(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Object beanInstance = getSingleton(beanName, false); |
|
|
|
|
|
|
|
if (beanInstance instanceof FactoryBean<?> factoryBean) { |
|
|
|
|
|
|
|
return factoryBean; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (isSingletonCurrentlyInCreation(beanName) || |
|
|
|
|
|
|
|
(mbd.getFactoryBeanName() != null && isSingletonCurrentlyInCreation(mbd.getFactoryBeanName()))) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object instance; |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
// Mark this bean as currently in creation, even if just partially.
|
|
|
|
BeanWrapper bw = this.factoryBeanInstanceCache.get(beanName); |
|
|
|
beforeSingletonCreation(beanName); |
|
|
|
if (bw != null) { |
|
|
|
// Give BeanPostProcessors a chance to return a proxy instead of the target bean instance.
|
|
|
|
return (FactoryBean<?>) bw.getWrappedInstance(); |
|
|
|
instance = resolveBeforeInstantiation(beanName, mbd); |
|
|
|
|
|
|
|
if (instance == null) { |
|
|
|
|
|
|
|
bw = createBeanInstance(beanName, mbd, null); |
|
|
|
|
|
|
|
instance = bw.getWrappedInstance(); |
|
|
|
|
|
|
|
this.factoryBeanInstanceCache.put(beanName, bw); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Object beanInstance = getSingleton(beanName, false); |
|
|
|
catch (UnsatisfiedDependencyException ex) { |
|
|
|
if (beanInstance instanceof FactoryBean<?> factoryBean) { |
|
|
|
// Don't swallow, probably misconfiguration...
|
|
|
|
return factoryBean; |
|
|
|
throw ex; |
|
|
|
} |
|
|
|
} |
|
|
|
if (isSingletonCurrentlyInCreation(beanName) || |
|
|
|
catch (BeanCreationException ex) { |
|
|
|
(mbd.getFactoryBeanName() != null && isSingletonCurrentlyInCreation(mbd.getFactoryBeanName()))) { |
|
|
|
// Don't swallow a linkage error since it contains a full stacktrace on
|
|
|
|
return null; |
|
|
|
// first occurrence... and just a plain NoClassDefFoundError afterwards.
|
|
|
|
} |
|
|
|
if (ex.contains(LinkageError.class)) { |
|
|
|
|
|
|
|
|
|
|
|
Object instance; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// Mark this bean as currently in creation, even if just partially.
|
|
|
|
|
|
|
|
beforeSingletonCreation(beanName); |
|
|
|
|
|
|
|
// Give BeanPostProcessors a chance to return a proxy instead of the target bean instance.
|
|
|
|
|
|
|
|
instance = resolveBeforeInstantiation(beanName, mbd); |
|
|
|
|
|
|
|
if (instance == null) { |
|
|
|
|
|
|
|
bw = createBeanInstance(beanName, mbd, null); |
|
|
|
|
|
|
|
instance = bw.getWrappedInstance(); |
|
|
|
|
|
|
|
this.factoryBeanInstanceCache.put(beanName, bw); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (UnsatisfiedDependencyException ex) { |
|
|
|
|
|
|
|
// Don't swallow, probably misconfiguration...
|
|
|
|
throw ex; |
|
|
|
throw ex; |
|
|
|
} |
|
|
|
} |
|
|
|
// Instantiation failure, maybe too early...
|
|
|
|
catch (BeanCreationException ex) { |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
// Don't swallow a linkage error since it contains a full stacktrace on
|
|
|
|
logger.debug("Bean creation exception on singleton FactoryBean type check: " + ex); |
|
|
|
// first occurrence... and just a plain NoClassDefFoundError afterwards.
|
|
|
|
|
|
|
|
if (ex.contains(LinkageError.class)) { |
|
|
|
|
|
|
|
throw ex; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Instantiation failure, maybe too early...
|
|
|
|
|
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
|
|
|
|
logger.debug("Bean creation exception on singleton FactoryBean type check: " + ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
onSuppressedException(ex); |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
onSuppressedException(ex); |
|
|
|
finally { |
|
|
|
return null; |
|
|
|
// Finished partial creation of this bean.
|
|
|
|
|
|
|
|
afterSingletonCreation(beanName); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return getFactoryBean(beanName, instance); |
|
|
|
} |
|
|
|
} |
|
|
|
finally { |
|
|
|
finally { |
|
|
|
// Finished partial creation of this bean.
|
|
|
|
this.singletonLock.unlock(); |
|
|
|
afterSingletonCreation(beanName); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return getFactoryBean(beanName, instance); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|