diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java index caab0eef84..82cc30af73 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java @@ -605,29 +605,32 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @Override public String[] getBeanNamesForAnnotation(Class annotationType) { - List results = new ArrayList<>(); + List result = new ArrayList<>(); for (String beanName : this.beanDefinitionNames) { BeanDefinition beanDefinition = getBeanDefinition(beanName); if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) { - results.add(beanName); + result.add(beanName); } } for (String beanName : this.manualSingletonNames) { - if (!results.contains(beanName) && findAnnotationOnBean(beanName, annotationType) != null) { - results.add(beanName); + if (!result.contains(beanName) && findAnnotationOnBean(beanName, annotationType) != null) { + result.add(beanName); } } - return StringUtils.toStringArray(results); + return StringUtils.toStringArray(result); } @Override public Map getBeansWithAnnotation(Class annotationType) { String[] beanNames = getBeanNamesForAnnotation(annotationType); - Map results = new LinkedHashMap<>(beanNames.length); + Map result = new LinkedHashMap<>(beanNames.length); for (String beanName : beanNames) { - results.put(beanName, getBean(beanName)); + Object beanInstance = getBean(beanName); + if (!(beanInstance instanceof NullBean)) { + result.put(beanName, beanInstance); + } } - return results; + return result; } /**