child bean definition's scope attribute can be inherited from parent bean definition now (SPR-3542)

This commit is contained in:
Juergen Hoeller
2009-11-12 00:09:05 +00:00
parent 4a25e2dde0
commit d0b6891275
6 changed files with 17 additions and 12 deletions

View File

@@ -118,9 +118,9 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
private volatile Object beanClass;
private String scope = SCOPE_SINGLETON;
private String scope;
private boolean singleton = true;
private boolean singleton = false;
private boolean prototype = false;
@@ -281,7 +281,9 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
if (other.getFactoryMethodName() != null) {
setFactoryMethodName(other.getFactoryMethodName());
}
setScope(other.getScope());
if (other.getScope() != null) {
setScope(other.getScope());
}
setAbstract(other.isAbstract());
setLazyInit(other.isLazyInit());
setRole(other.getRole());
@@ -408,7 +410,6 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
* @see #SCOPE_PROTOTYPE
*/
public void setScope(String scope) {
Assert.notNull(scope, "Scope must not be null");
this.scope = scope;
this.singleton = SCOPE_SINGLETON.equals(scope);
this.prototype = SCOPE_PROTOTYPE.equals(scope);

View File

@@ -1113,6 +1113,11 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
mbd.overrideFrom(bd);
}
// Set default singleton scope, if not configured before.
if (mbd.getScope() == null) {
mbd.setScope(RootBeanDefinition.SCOPE_SINGLETON);
}
// A bean contained in a non-singleton bean cannot be a singleton itself.
// Let's correct this on the fly here, since this might be the result of
// parent-child merging for the outer bean, in which case the original inner bean

View File

@@ -535,8 +535,7 @@ public class BeanDefinitionParserDelegate {
}
String lazyInit = ele.getAttribute(LAZY_INIT_ATTRIBUTE);
if (DEFAULT_VALUE.equals(lazyInit) && bd.isSingleton()) {
// Just apply default to singletons, as lazy-init has no meaning for prototypes.
if (DEFAULT_VALUE.equals(lazyInit)) {
lazyInit = this.defaults.getLazyInit();
}
bd.setLazyInit(TRUE_VALUE.equals(lazyInit));