diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java b/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java index 25fb238fb11..570ebfb7e2a 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java @@ -168,22 +168,25 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat } } - boolean cacheable = true; - for (String autowiredBeanName : autowiredBeanNames) { - if (!this.beanFactory.containsBean(autowiredBeanName)) { - cacheable = false; - } - else { - if (this.beanName != null) { - this.beanFactory.registerDependentBean(autowiredBeanName, this.beanName); - } - if (!this.beanFactory.isSingleton(autowiredBeanName)) { + boolean cacheable = false; + if (!autowiredBeanNames.isEmpty()) { + cacheable = true; + for (String autowiredBeanName : autowiredBeanNames) { + if (!this.beanFactory.containsBean(autowiredBeanName)) { cacheable = false; } + else { + if (this.beanName != null) { + this.beanFactory.registerDependentBean(autowiredBeanName, this.beanName); + } + if (!this.beanFactory.isSingleton(autowiredBeanName)) { + cacheable = false; + } + } } - if (cacheable) { - this.cachedTarget = target; - } + } + if (cacheable) { + this.cachedTarget = target; } return target;