提交 242ecdc4 编写于 作者: J Juergen Hoeller

Fixed inner bean name determination for multi-level nesting scenario,...

Fixed inner bean name determination for multi-level nesting scenario, calculating a unique bean name as early as possible now (and for any kind of bean scope)

Our per-bean caching in AutowiredAnnotationBeanPostProcessor and co relies on unique bean names, so this change fixes potential cache mismatch problems occuring there.

Issue: SPR-11131
上级 5dcd2876
......@@ -256,10 +256,8 @@ class BeanDefinitionValueResolver {
mbd = this.beanFactory.getMergedBeanDefinition(innerBeanName, innerBd, this.beanDefinition);
// Check given bean name whether it is unique. If not already unique,
// add counter - increasing the counter until the name is unique.
String actualInnerBeanName = innerBeanName;
if (mbd.isSingleton()) {
actualInnerBeanName = adaptInnerBeanName(innerBeanName);
}
String actualInnerBeanName = adaptInnerBeanName(innerBeanName);
this.beanFactory.registerContainedBean(actualInnerBeanName, this.beanName);
// Guarantee initialization of beans that the inner bean depends on.
String[] dependsOn = mbd.getDependsOn();
if (dependsOn != null) {
......@@ -269,7 +267,6 @@ class BeanDefinitionValueResolver {
}
}
Object innerBean = this.beanFactory.createBean(actualInnerBeanName, mbd, null);
this.beanFactory.registerContainedBean(actualInnerBeanName, this.beanName);
if (innerBean instanceof FactoryBean) {
boolean synthetic = mbd.isSynthetic();
return this.beanFactory.getObjectFromFactoryBean((FactoryBean<?>) innerBean, actualInnerBeanName, !synthetic);
......
......@@ -16,17 +16,6 @@
package org.springframework.beans.factory.xml;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
......@@ -39,6 +28,8 @@ import java.util.Map;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.xml.sax.InputSource;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException;
......@@ -73,7 +64,9 @@ import org.springframework.tests.sample.beans.factory.DummyFactory;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.SerializationTestUtils;
import org.springframework.util.StopWatch;
import org.xml.sax.InputSource;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
/**
* Miscellaneous tests for XML bean definitions.
......@@ -256,7 +249,7 @@ public final class XmlBeanFactoryTests {
assertEquals(5, hasInnerBeans.getAge());
TestBean inner1 = (TestBean) hasInnerBeans.getSpouse();
assertNotNull(inner1);
assertEquals("innerBean", inner1.getBeanName());
assertTrue(inner1.getBeanName().startsWith("innerBean"));
assertEquals("inner1", inner1.getName());
assertEquals(6, inner1.getAge());
......@@ -271,7 +264,7 @@ public final class XmlBeanFactoryTests {
TestBean innerFactory = (TestBean) friends[1];
assertEquals(DummyFactory.SINGLETON_NAME, innerFactory.getName());
TestBean inner5 = (TestBean) friends[2];
assertEquals("innerBean", inner5.getBeanName());
assertTrue(inner5.getBeanName().startsWith("innerBean"));
}
@Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册