fixed decorated BeanDefinition condition for early type checking in AbstractBeanFactory (SPR-7006)
This commit is contained in:
parent
20f4e9023b
commit
092241a632
|
|
@ -480,7 +480,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||||
// Check decorated bean definition, if any: We assume it'll be easier
|
// Check decorated bean definition, if any: We assume it'll be easier
|
||||||
// to determine the decorated bean's type than the proxy's type.
|
// to determine the decorated bean's type than the proxy's type.
|
||||||
BeanDefinitionHolder dbd = mbd.getDecoratedDefinition();
|
BeanDefinitionHolder dbd = mbd.getDecoratedDefinition();
|
||||||
if (dbd != null) {
|
if (dbd != null && !BeanFactoryUtils.isFactoryDereference(name)) {
|
||||||
RootBeanDefinition tbd = getMergedBeanDefinition(dbd.getBeanName(), dbd.getBeanDefinition(), mbd);
|
RootBeanDefinition tbd = getMergedBeanDefinition(dbd.getBeanName(), dbd.getBeanDefinition(), mbd);
|
||||||
Class targetClass = predictBeanType(dbd.getBeanName(), tbd, FactoryBean.class, typeToMatch);
|
Class targetClass = predictBeanType(dbd.getBeanName(), tbd, FactoryBean.class, typeToMatch);
|
||||||
if (targetClass != null && !FactoryBean.class.isAssignableFrom(targetClass)) {
|
if (targetClass != null && !FactoryBean.class.isAssignableFrom(targetClass)) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@
|
||||||
xmlns:util="http://www.springframework.org/schema/util"
|
xmlns:util="http://www.springframework.org/schema/util"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
|
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
|
||||||
http://www.springframework.org/schema/beans/test http://www.springframework.org/schema/beans/factory/xml/support/CustomNamespaceHandlerTests.xsd">
|
http://www.springframework.org/schema/beans/test http://www.springframework.org/schema/beans/factory/xml/support/CustomNamespaceHandlerTests.xsd"
|
||||||
|
default-lazy-init="true">
|
||||||
|
|
||||||
<test:testBean id="testBean" name="Rob Harrop" age="23"/>
|
<test:testBean id="testBean" name="Rob Harrop" age="23"/>
|
||||||
|
|
||||||
|
|
@ -19,7 +20,7 @@
|
||||||
<property name="age" value="23"/>
|
<property name="age" value="23"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="debuggingTestBeanNoInstance" class="org.springframework.beans.ITestBean">
|
<bean id="debuggingTestBeanNoInstance" class="org.springframework.context.ApplicationListener">
|
||||||
<test:debug/>
|
<test:debug/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.beans.factory.xml.PluggableSchemaResolver;
|
import org.springframework.beans.factory.xml.PluggableSchemaResolver;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
|
import org.springframework.context.ApplicationListener;
|
||||||
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
|
|
||||||
|
|
@ -77,17 +79,18 @@ public class CustomNamespaceHandlerTests {
|
||||||
private static final String NS_XML = format("%s/%s-context.xml", FQ_PATH, CLASSNAME);
|
private static final String NS_XML = format("%s/%s-context.xml", FQ_PATH, CLASSNAME);
|
||||||
private static final String TEST_XSD = format("%s/%s.xsd", FQ_PATH, CLASSNAME);
|
private static final String TEST_XSD = format("%s/%s.xsd", FQ_PATH, CLASSNAME);
|
||||||
|
|
||||||
private DefaultListableBeanFactory beanFactory;
|
private GenericApplicationContext beanFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
|
NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
|
||||||
this.beanFactory = new DefaultListableBeanFactory();
|
this.beanFactory = new GenericApplicationContext();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
|
||||||
reader.setNamespaceHandlerResolver(resolver);
|
reader.setNamespaceHandlerResolver(resolver);
|
||||||
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
|
||||||
reader.setEntityResolver(new DummySchemaResolver());
|
reader.setEntityResolver(new DummySchemaResolver());
|
||||||
reader.loadBeanDefinitions(getResource());
|
reader.loadBeanDefinitions(getResource());
|
||||||
|
this.beanFactory.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -115,7 +118,7 @@ public class CustomNamespaceHandlerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProxyingDecoratorNoInstance() throws Exception {
|
public void testProxyingDecoratorNoInstance() throws Exception {
|
||||||
String[] beanNames = this.beanFactory.getBeanNamesForType(ITestBean.class);
|
String[] beanNames = this.beanFactory.getBeanNamesForType(ApplicationListener.class);
|
||||||
assertTrue(Arrays.asList(beanNames).contains("debuggingTestBeanNoInstance"));
|
assertTrue(Arrays.asList(beanNames).contains("debuggingTestBeanNoInstance"));
|
||||||
try {
|
try {
|
||||||
this.beanFactory.getBean("debuggingTestBeanNoInstance");
|
this.beanFactory.getBean("debuggingTestBeanNoInstance");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue