Skip to content

Commit 5a04ed5

Browse files
committed
registered plain singletons will be fully matched according to their qualifiers; "systemProperties" bean is not considered a default match for type Properties anymore (SPR-5355)
1 parent 6086bb3 commit 5a04ed5

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -393,14 +393,13 @@ public boolean isAutowireCandidate(String beanName, DependencyDescriptor descrip
393393

394394
if (!containsBeanDefinition(beanName)) {
395395
if (containsSingleton(beanName)) {
396-
return true;
396+
return isAutowireCandidate(beanName, new RootBeanDefinition(getType(beanName)), descriptor);
397397
}
398398
else if (getParentBeanFactory() instanceof ConfigurableListableBeanFactory) {
399399
// No bean definition found in this factory -> delegate to parent.
400400
return ((ConfigurableListableBeanFactory) getParentBeanFactory()).isAutowireCandidate(beanName, descriptor);
401401
}
402402
}
403-
404403
return isAutowireCandidate(beanName, getMergedLocalBeanDefinition(beanName), descriptor);
405404
}
406405

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@
4141
</qualifier>
4242
</bean>
4343

44-
</beans>
44+
<bean id="testProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"/>
45+
46+
</beans>

org.springframework.context/src/test/java/org/springframework/beans/factory/xml/QualifierAnnotationTests.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
import java.lang.annotation.Retention;
2525
import java.lang.annotation.RetentionPolicy;
2626
import java.lang.annotation.Target;
27+
import java.util.Properties;
2728

2829
import org.junit.Test;
2930
import org.springframework.beans.factory.BeanCreationException;
@@ -82,6 +83,7 @@ public void testQualifiedByBeanName() {
8283
QualifiedByBeanNameTestBean testBean = (QualifiedByBeanNameTestBean) context.getBean("testBean");
8384
Person person = testBean.getLarry();
8485
assertEquals("LarryBean", person.getName());
86+
assertTrue(testBean.myProps != null && testBean.myProps.isEmpty());
8587
}
8688

8789
@Test
@@ -192,6 +194,9 @@ private static class QualifiedByBeanNameTestBean {
192194
@Autowired @Qualifier("larryBean")
193195
private Person larry;
194196

197+
@Autowired @Qualifier("testProperties")
198+
public Properties myProps;
199+
195200
public Person getLarry() {
196201
return larry;
197202
}

0 commit comments

Comments
 (0)