Injected Map/Collection does not include null bean entries

Issue: SPR-17034
This commit is contained in:
Juergen Hoeller
2018-07-16 13:04:38 +02:00
parent faef363e85
commit 77d72f1e01
2 changed files with 11 additions and 6 deletions

View File

@@ -1318,7 +1318,13 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
private void addCandidateEntry(Map<String, Object> candidates, String candidateName,
DependencyDescriptor descriptor, Class<?> requiredType) {
if (descriptor instanceof MultiElementDescriptor || containsSingleton(candidateName)) {
if (descriptor instanceof MultiElementDescriptor) {
Object beanInstance = descriptor.resolveCandidate(candidateName, requiredType, this);
if (!(beanInstance instanceof NullBean)) {
candidates.put(candidateName, beanInstance);
}
}
else if (containsSingleton(candidateName)) {
Object beanInstance = descriptor.resolveCandidate(candidateName, requiredType, this);
candidates.put(candidateName, (beanInstance instanceof NullBean ? null : beanInstance));
}