DefaultSingletonBeanRegistry's isDependent defensively checks for circular recursion

Issue: SPR-10787
This commit is contained in:
Juergen Hoeller
2014-12-07 16:30:31 +01:00
parent 1daa5eb383
commit 15d3b88037
2 changed files with 34 additions and 3 deletions

View File

@@ -14,12 +14,12 @@
* limitations under the License.
*/
package org.springframework.beans.factory;
package org.springframework.beans.factory.support;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.tests.sample.beans.DerivedTestBean;
import org.springframework.tests.sample.beans.TestBean;
@@ -83,4 +83,22 @@ public class DefaultSingletonBeanRegistryTests {
assertTrue(tb.wasDestroyed());
}
@Test
public void testDependentRegistration() {
DefaultSingletonBeanRegistry beanRegistry = new DefaultSingletonBeanRegistry();
beanRegistry.registerDependentBean("a", "b");
beanRegistry.registerDependentBean("b", "c");
beanRegistry.registerDependentBean("c", "b");
assertTrue(beanRegistry.isDependent("a", "b"));
assertTrue(beanRegistry.isDependent("b", "c"));
assertTrue(beanRegistry.isDependent("c", "b"));
assertTrue(beanRegistry.isDependent("a", "c"));
assertFalse(beanRegistry.isDependent("c", "a"));
assertFalse(beanRegistry.isDependent("b", "a"));
assertFalse(beanRegistry.isDependent("a", "a"));
assertTrue(beanRegistry.isDependent("b", "b"));
assertTrue(beanRegistry.isDependent("c", "c"));
}
}