@@ -1147,7 +1147,7 @@ private Object resolveMultipleBeans(DependencyDescriptor descriptor, String bean
1147
1147
if (type .isArray ()) {
1148
1148
Class <?> componentType = type .getComponentType ();
1149
1149
Map <String , Object > matchingBeans = findAutowireCandidates (beanName , componentType ,
1150
- new MultiElementDependencyDescriptor (descriptor ));
1150
+ new MultiElementDescriptor (descriptor ));
1151
1151
if (matchingBeans .isEmpty ()) {
1152
1152
return null ;
1153
1153
}
@@ -1167,7 +1167,7 @@ else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {
1167
1167
return null ;
1168
1168
}
1169
1169
Map <String , Object > matchingBeans = findAutowireCandidates (beanName , elementType ,
1170
- new MultiElementDependencyDescriptor (descriptor ));
1170
+ new MultiElementDescriptor (descriptor ));
1171
1171
if (matchingBeans .isEmpty ()) {
1172
1172
return null ;
1173
1173
}
@@ -1191,7 +1191,7 @@ else if (Map.class.isAssignableFrom(type) && type.isInterface()) {
1191
1191
return null ;
1192
1192
}
1193
1193
Map <String , Object > matchingBeans = findAutowireCandidates (beanName , valueType ,
1194
- new MultiElementDependencyDescriptor (descriptor ));
1194
+ new MultiElementDescriptor (descriptor ));
1195
1195
if (matchingBeans .isEmpty ()) {
1196
1196
return null ;
1197
1197
}
@@ -1258,25 +1258,27 @@ protected Map<String, Object> findAutowireCandidates(
1258
1258
}
1259
1259
}
1260
1260
}
1261
- for (String candidateName : candidateNames ) {
1262
- if (!isSelfReference (beanName , candidateName ) && isAutowireCandidate (candidateName , descriptor )) {
1263
- addCandidateEntry (result , candidateName , descriptor , requiredType );
1261
+ for (String candidate : candidateNames ) {
1262
+ if (!isSelfReference (beanName , candidate ) && isAutowireCandidate (candidate , descriptor )) {
1263
+ addCandidateEntry (result , candidate , descriptor , requiredType );
1264
1264
}
1265
1265
}
1266
1266
if (result .isEmpty () && !indicatesMultipleBeans (requiredType )) {
1267
1267
// Consider fallback matches if the first pass failed to find anything...
1268
1268
DependencyDescriptor fallbackDescriptor = descriptor .forFallbackMatch ();
1269
- for (String candidateName : candidateNames ) {
1270
- if (!isSelfReference (beanName , candidateName ) && isAutowireCandidate (candidateName , fallbackDescriptor )) {
1271
- addCandidateEntry (result , candidateName , descriptor , requiredType );
1269
+ for (String candidate : candidateNames ) {
1270
+ if (!isSelfReference (beanName , candidate ) && isAutowireCandidate (candidate , fallbackDescriptor )) {
1271
+ addCandidateEntry (result , candidate , descriptor , requiredType );
1272
1272
}
1273
1273
}
1274
- if (result .isEmpty () && !( descriptor instanceof MultiElementDependencyDescriptor ) ) {
1274
+ if (result .isEmpty ()) {
1275
1275
// Consider self references as a final pass...
1276
- // but not as collection elements, just for direct dependency declarations.
1277
- for (String candidateName : candidateNames ) {
1278
- if (isSelfReference (beanName , candidateName ) && isAutowireCandidate (candidateName , fallbackDescriptor )) {
1279
- addCandidateEntry (result , candidateName , descriptor , requiredType );
1276
+ // but in the case of a dependency collection, not the very same bean itself.
1277
+ for (String candidate : candidateNames ) {
1278
+ if (isSelfReference (beanName , candidate ) &&
1279
+ (!(descriptor instanceof MultiElementDescriptor ) || !beanName .equals (candidate )) &&
1280
+ isAutowireCandidate (candidate , fallbackDescriptor )) {
1281
+ addCandidateEntry (result , candidate , descriptor , requiredType );
1280
1282
}
1281
1283
}
1282
1284
}
@@ -1291,7 +1293,7 @@ protected Map<String, Object> findAutowireCandidates(
1291
1293
private void addCandidateEntry (Map <String , Object > candidates , String candidateName ,
1292
1294
DependencyDescriptor descriptor , Class <?> requiredType ) {
1293
1295
1294
- if (descriptor instanceof MultiElementDependencyDescriptor || containsSingleton (candidateName )) {
1296
+ if (descriptor instanceof MultiElementDescriptor || containsSingleton (candidateName )) {
1295
1297
candidates .put (candidateName , descriptor .resolveCandidate (candidateName , requiredType , this ));
1296
1298
}
1297
1299
else {
@@ -1745,9 +1747,9 @@ public NestedDependencyDescriptor(DependencyDescriptor original) {
1745
1747
}
1746
1748
1747
1749
1748
- private static class MultiElementDependencyDescriptor extends NestedDependencyDescriptor {
1750
+ private static class MultiElementDescriptor extends NestedDependencyDescriptor {
1749
1751
1750
- public MultiElementDependencyDescriptor (DependencyDescriptor original ) {
1752
+ public MultiElementDescriptor (DependencyDescriptor original ) {
1751
1753
super (original );
1752
1754
}
1753
1755
}
0 commit comments