Skip to content

Commit 092241a

Browse files
committed
fixed decorated BeanDefinition condition for early type checking in AbstractBeanFactory (SPR-7006)
1 parent 20f4e90 commit 092241a

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public boolean isTypeMatch(String name, Class targetType) throws NoSuchBeanDefin
480480
// Check decorated bean definition, if any: We assume it'll be easier
481481
// to determine the decorated bean's type than the proxy's type.
482482
BeanDefinitionHolder dbd = mbd.getDecoratedDefinition();
483-
if (dbd != null) {
483+
if (dbd != null && !BeanFactoryUtils.isFactoryDereference(name)) {
484484
RootBeanDefinition tbd = getMergedBeanDefinition(dbd.getBeanName(), dbd.getBeanDefinition(), mbd);
485485
Class targetClass = predictBeanType(dbd.getBeanName(), tbd, FactoryBean.class, typeToMatch);
486486
if (targetClass != null && !FactoryBean.class.isAssignableFrom(targetClass)) {

org.springframework.context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests-context.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
xmlns:util="http://www.springframework.org/schema/util"
66
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
77
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
8-
http://www.springframework.org/schema/beans/test http://www.springframework.org/schema/beans/factory/xml/support/CustomNamespaceHandlerTests.xsd">
8+
http://www.springframework.org/schema/beans/test http://www.springframework.org/schema/beans/factory/xml/support/CustomNamespaceHandlerTests.xsd"
9+
default-lazy-init="true">
910

1011
<test:testBean id="testBean" name="Rob Harrop" age="23"/>
1112

@@ -19,7 +20,7 @@
1920
<property name="age" value="23"/>
2021
</bean>
2122

22-
<bean id="debuggingTestBeanNoInstance" class="org.springframework.beans.ITestBean">
23+
<bean id="debuggingTestBeanNoInstance" class="org.springframework.context.ApplicationListener">
2324
<test:debug/>
2425
</bean>
2526

org.springframework.context/src/test/java/org/springframework/beans/factory/xml/support/CustomNamespaceHandlerTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import org.springframework.beans.factory.xml.ParserContext;
5858
import org.springframework.beans.factory.xml.PluggableSchemaResolver;
5959
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
60+
import org.springframework.context.ApplicationListener;
61+
import org.springframework.context.support.GenericApplicationContext;
6062
import org.springframework.core.io.ClassPathResource;
6163
import org.springframework.core.io.Resource;
6264

@@ -77,17 +79,18 @@ public class CustomNamespaceHandlerTests {
7779
private static final String NS_XML = format("%s/%s-context.xml", FQ_PATH, CLASSNAME);
7880
private static final String TEST_XSD = format("%s/%s.xsd", FQ_PATH, CLASSNAME);
7981

80-
private DefaultListableBeanFactory beanFactory;
82+
private GenericApplicationContext beanFactory;
8183

8284
@Before
8385
public void setUp() throws Exception {
8486
NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(CLASS.getClassLoader(), NS_PROPS);
85-
this.beanFactory = new DefaultListableBeanFactory();
87+
this.beanFactory = new GenericApplicationContext();
8688
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
8789
reader.setNamespaceHandlerResolver(resolver);
8890
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
8991
reader.setEntityResolver(new DummySchemaResolver());
9092
reader.loadBeanDefinitions(getResource());
93+
this.beanFactory.refresh();
9194
}
9295

9396

@@ -115,7 +118,7 @@ public void testProxyingDecorator() throws Exception {
115118

116119
@Test
117120
public void testProxyingDecoratorNoInstance() throws Exception {
118-
String[] beanNames = this.beanFactory.getBeanNamesForType(ITestBean.class);
121+
String[] beanNames = this.beanFactory.getBeanNamesForType(ApplicationListener.class);
119122
assertTrue(Arrays.asList(beanNames).contains("debuggingTestBeanNoInstance"));
120123
try {
121124
this.beanFactory.getBean("debuggingTestBeanNoInstance");

0 commit comments

Comments
 (0)