Properly resolve null beans as getBeansOfType result entries
Issue: SPR-16163
This commit is contained in:
parent
2d1f87501c
commit
9649b0cb25
|
@ -505,6 +505,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Map<String, T> getBeansOfType(@Nullable Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
|
||||
throws BeansException {
|
||||
|
||||
|
@ -512,7 +513,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
Map<String, T> result = new LinkedHashMap<>(beanNames.length);
|
||||
for (String beanName : beanNames) {
|
||||
try {
|
||||
result.put(beanName, getBean(beanName, type));
|
||||
Object beanInstance = getBean(beanName);
|
||||
result.put(beanName, (beanInstance instanceof NullBean ? null : (T) beanInstance));
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable rootCause = ex.getMostSpecificCause();
|
||||
|
|
|
@ -701,6 +701,11 @@ public class AutowiredAnnotationBeanPostProcessorTests {
|
|||
assertEquals(2, bean.getNestedTestBeans().size());
|
||||
assertNull(bean.getNestedTestBeans().get(0));
|
||||
assertSame(ntb2, bean.getNestedTestBeans().get(1));
|
||||
|
||||
Map<String, NestedTestBean> map = bf.getBeansOfType(NestedTestBean.class);
|
||||
assertNull(map.get("nestedTestBean1"));
|
||||
assertSame(ntb2, map.get("nestedTestBean2"));
|
||||
|
||||
bf.destroySingletons();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue