Document destruction callback behavior for inner beans in case of scope mismatch

This commit undoes the previous refinement and rather documents the original behavior.

Issue: SPR-13739
This commit is contained in:
Juergen Hoeller
2015-11-30 21:57:54 +01:00
parent 8ed2c470be
commit 998da2f45c
5 changed files with 50 additions and 65 deletions

View File

@@ -1251,14 +1251,15 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
// Set default singleton scope, if not configured before.
if (!StringUtils.hasLength(mbd.getScope())) {
mbd.setScope(BeanDefinition.SCOPE_SINGLETON);
mbd.setScope(RootBeanDefinition.SCOPE_SINGLETON);
}
// Check for a mismatch between an inner bean's scope and its containing
// bean's scope: For example, a bean contained in a non-singleton bean
// cannot be a singleton itself. Let's correct this on the fly here.
if (containingBd != null && !mbd.isPrototype() && !mbd.getScope().equals(containingBd.getScope())) {
mbd.setScope(containingBd.isSingleton() ? BeanDefinition.SCOPE_PROTOTYPE : containingBd.getScope());
// 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
// definition will not have inherited the merged outer bean's singleton status.
if (containingBd != null && !containingBd.isSingleton() && mbd.isSingleton()) {
mbd.setScope(containingBd.getScope());
}
// Only cache the merged bean definition if we're already about to create an