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

@@ -2548,39 +2548,6 @@ public class DefaultListableBeanFactoryTests {
assertEquals("Destroy methods invoked", 1, BeanWithDestroyMethod.closeCount);
}
@Test
public void testDestroyMethodOnInnerBeanAsCustomScope() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition innerBd = new RootBeanDefinition(BeanWithDestroyMethod.class);
innerBd.setScope("custom");
innerBd.setDestroyMethodName("close");
RootBeanDefinition bd = new RootBeanDefinition(BeanWithDestroyMethod.class);
bd.setDestroyMethodName("close");
bd.getPropertyValues().add("inner", innerBd);
lbf.registerBeanDefinition("test", bd);
BeanWithDestroyMethod.closeCount = 0;
lbf.preInstantiateSingletons();
lbf.destroySingletons();
assertEquals("Destroy methods not invoked", 1, BeanWithDestroyMethod.closeCount);
}
@Test
public void testDestroyMethodOnInnerBeanAsCustomScopeWithinPrototype() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition innerBd = new RootBeanDefinition(BeanWithDestroyMethod.class);
innerBd.setScope("custom");
innerBd.setDestroyMethodName("close");
RootBeanDefinition bd = new RootBeanDefinition(BeanWithDestroyMethod.class);
bd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
bd.setDestroyMethodName("close");
bd.getPropertyValues().add("inner", innerBd);
lbf.registerBeanDefinition("test", bd);
BeanWithDestroyMethod.closeCount = 0;
Object prototypeInstance = lbf.getBean("test");
lbf.destroyBean("test", prototypeInstance);
assertEquals("Destroy methods not invoked", 1, BeanWithDestroyMethod.closeCount);
}
@Test
public void testFindTypeOfSingletonFactoryMethodOnBeanInstance() {
findTypeOfPrototypeFactoryMethodOnBeanInstance(true);