@@ -1137,7 +1137,7 @@ private Object resolveMultipleBeans(DependencyDescriptor descriptor, String bean
1137
1137
if (type .isArray ()) {
1138
1138
Class <?> componentType = type .getComponentType ();
1139
1139
Map <String , Object > matchingBeans = findAutowireCandidates (beanName , componentType ,
1140
- new MultiElementDependencyDescriptor (descriptor ));
1140
+ new MultiElementDescriptor (descriptor ));
1141
1141
if (matchingBeans .isEmpty ()) {
1142
1142
return null ;
1143
1143
}
@@ -1157,7 +1157,7 @@ else if (Collection.class.isAssignableFrom(type) && type.isInterface()) {
1157
1157
return null ;
1158
1158
}
1159
1159
Map <String , Object > matchingBeans = findAutowireCandidates (beanName , elementType ,
1160
- new MultiElementDependencyDescriptor (descriptor ));
1160
+ new MultiElementDescriptor (descriptor ));
1161
1161
if (matchingBeans .isEmpty ()) {
1162
1162
return null ;
1163
1163
}
@@ -1181,7 +1181,7 @@ else if (Map.class.isAssignableFrom(type) && type.isInterface()) {
1181
1181
return null ;
1182
1182
}
1183
1183
Map <String , Object > matchingBeans = findAutowireCandidates (beanName , valueType ,
1184
- new MultiElementDependencyDescriptor (descriptor ));
1184
+ new MultiElementDescriptor (descriptor ));
1185
1185
if (matchingBeans .isEmpty ()) {
1186
1186
return null ;
1187
1187
}
@@ -1248,25 +1248,27 @@ protected Map<String, Object> findAutowireCandidates(
1248
1248
}
1249
1249
}
1250
1250
}
1251
- for (String candidateName : candidateNames ) {
1252
- if (!isSelfReference (beanName , candidateName ) && isAutowireCandidate (candidateName , descriptor )) {
1253
- addCandidateEntry (result , candidateName , descriptor , requiredType );
1251
+ for (String candidate : candidateNames ) {
1252
+ if (!isSelfReference (beanName , candidate ) && isAutowireCandidate (candidate , descriptor )) {
1253
+ addCandidateEntry (result , candidate , descriptor , requiredType );
1254
1254
}
1255
1255
}
1256
1256
if (result .isEmpty () && !indicatesMultipleBeans (requiredType )) {
1257
1257
// Consider fallback matches if the first pass failed to find anything...
1258
1258
DependencyDescriptor fallbackDescriptor = descriptor .forFallbackMatch ();
1259
- for (String candidateName : candidateNames ) {
1260
- if (!isSelfReference (beanName , candidateName ) && isAutowireCandidate (candidateName , fallbackDescriptor )) {
1261
- addCandidateEntry (result , candidateName , descriptor , requiredType );
1259
+ for (String candidate : candidateNames ) {
1260
+ if (!isSelfReference (beanName , candidate ) && isAutowireCandidate (candidate , fallbackDescriptor )) {
1261
+ addCandidateEntry (result , candidate , descriptor , requiredType );
1262
1262
}
1263
1263
}
1264
- if (result .isEmpty () && !( descriptor instanceof MultiElementDependencyDescriptor ) ) {
1264
+ if (result .isEmpty ()) {
1265
1265
// Consider self references as a final pass...
1266
- // but not as collection elements, just for direct dependency declarations.
1267
- for (String candidateName : candidateNames ) {
1268
- if (isSelfReference (beanName , candidateName ) && isAutowireCandidate (candidateName , fallbackDescriptor )) {
1269
- addCandidateEntry (result , candidateName , descriptor , requiredType );
1266
+ // but in the case of a dependency collection, not the very same bean itself.
1267
+ for (String candidate : candidateNames ) {
1268
+ if (isSelfReference (beanName , candidate ) &&
1269
+ (!(descriptor instanceof MultiElementDescriptor ) || !beanName .equals (candidate )) &&
1270
+ isAutowireCandidate (candidate , fallbackDescriptor )) {
1271
+ addCandidateEntry (result , candidate , descriptor , requiredType );
1270
1272
}
1271
1273
}
1272
1274
}
@@ -1281,7 +1283,7 @@ protected Map<String, Object> findAutowireCandidates(
1281
1283
private void addCandidateEntry (Map <String , Object > candidates , String candidateName ,
1282
1284
DependencyDescriptor descriptor , Class <?> requiredType ) {
1283
1285
1284
- if (descriptor instanceof MultiElementDependencyDescriptor || containsSingleton (candidateName )) {
1286
+ if (descriptor instanceof MultiElementDescriptor || containsSingleton (candidateName )) {
1285
1287
candidates .put (candidateName , descriptor .resolveCandidate (candidateName , requiredType , this ));
1286
1288
}
1287
1289
else {
@@ -1730,9 +1732,9 @@ public NestedDependencyDescriptor(DependencyDescriptor original) {
1730
1732
}
1731
1733
1732
1734
1733
- private static class MultiElementDependencyDescriptor extends NestedDependencyDescriptor {
1735
+ private static class MultiElementDescriptor extends NestedDependencyDescriptor {
1734
1736
1735
- public MultiElementDependencyDescriptor (DependencyDescriptor original ) {
1737
+ public MultiElementDescriptor (DependencyDescriptor original ) {
1736
1738
super (original );
1737
1739
}
1738
1740
}
0 commit comments