Skip to content

Commit b25f983

Browse files
committed
Tighten cacheable decision behind @lazy injection point
Closes gh-35917 (cherry picked from commit 61d5413)
1 parent c2f7cd3 commit b25f983

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,25 @@ else if (target instanceof Collection<?> coll && Collection.class == getTargetCl
172172
}
173173
}
174174

175-
boolean cacheable = true;
176-
for (String autowiredBeanName : autowiredBeanNames) {
177-
if (!this.beanFactory.containsBean(autowiredBeanName)) {
178-
cacheable = false;
179-
}
180-
else {
181-
if (this.beanName != null) {
182-
this.beanFactory.registerDependentBean(autowiredBeanName, this.beanName);
183-
}
184-
if (!this.beanFactory.isSingleton(autowiredBeanName)) {
175+
boolean cacheable = false;
176+
if (!autowiredBeanNames.isEmpty()) {
177+
cacheable = true;
178+
for (String autowiredBeanName : autowiredBeanNames) {
179+
if (!this.beanFactory.containsBean(autowiredBeanName)) {
185180
cacheable = false;
186181
}
182+
else {
183+
if (this.beanName != null) {
184+
this.beanFactory.registerDependentBean(autowiredBeanName, this.beanName);
185+
}
186+
if (!this.beanFactory.isSingleton(autowiredBeanName)) {
187+
cacheable = false;
188+
}
189+
}
187190
}
188-
if (cacheable) {
189-
this.cachedTarget = target;
190-
}
191+
}
192+
if (cacheable) {
193+
this.cachedTarget = target;
191194
}
192195

193196
return target;

0 commit comments

Comments
 (0)