LazyInitTargetSource works for @Bean targets as well
Issue: SPR-10508 Issue: SPR-8080
This commit is contained in:
@@ -372,6 +372,10 @@ class ConstructorResolver {
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"factory-bean '" + factoryBeanName + "' (or a BeanPostProcessor involved) returned null");
|
||||
}
|
||||
if (mbd.isSingleton() && this.beanFactory.containsSingleton(beanName)) {
|
||||
throw new IllegalStateException("About-to-be-created singleton instance implicitly appeared " +
|
||||
"through the creation of the factory bean that its bean definition points to");
|
||||
}
|
||||
factoryClass = factoryBean.getClass();
|
||||
isStatic = false;
|
||||
}
|
||||
@@ -904,4 +908,5 @@ class ConstructorResolver {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -220,12 +220,22 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
logger.debug("Creating shared instance of singleton bean '" + beanName + "'");
|
||||
}
|
||||
beforeSingletonCreation(beanName);
|
||||
boolean newSingleton = false;
|
||||
boolean recordSuppressedExceptions = (this.suppressedExceptions == null);
|
||||
if (recordSuppressedExceptions) {
|
||||
this.suppressedExceptions = new LinkedHashSet<Exception>();
|
||||
}
|
||||
try {
|
||||
singletonObject = singletonFactory.getObject();
|
||||
newSingleton = true;
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// Has the singleton object implicitly appeared in the meantime ->
|
||||
// if yes, proceed with it since the exception indicates that state.
|
||||
singletonObject = this.singletonObjects.get(beanName);
|
||||
if (singletonObject == null) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
if (recordSuppressedExceptions) {
|
||||
@@ -241,7 +251,9 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
|
||||
}
|
||||
afterSingletonCreation(beanName);
|
||||
}
|
||||
addSingleton(beanName, singletonObject);
|
||||
if (newSingleton) {
|
||||
addSingleton(beanName, singletonObject);
|
||||
}
|
||||
}
|
||||
return (singletonObject != NULL_OBJECT ? singletonObject : null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user