@@ -418,8 +418,11 @@ private String[] doGetBeanNamesForType(ResolvableType type, boolean includeNonSi
418
418
!requiresEagerInitForType (mbd .getFactoryBeanName ()))) {
419
419
// In case of FactoryBean, match object created by FactoryBean.
420
420
boolean isFactoryBean = isFactoryBean (beanName , mbd );
421
- boolean matchFound = (allowEagerInit || !isFactoryBean || containsSingleton (beanName )) &&
422
- (includeNonSingletons || isSingleton (beanName )) && isTypeMatch (beanName , type );
421
+ boolean matchFound = (allowEagerInit || !isFactoryBean ||
422
+ (mbd .getDecoratedDefinition () != null && !mbd .isLazyInit ()) ||
423
+ containsSingleton (beanName )) &&
424
+ (includeNonSingletons || isSingleton (beanName )) &&
425
+ isTypeMatch (beanName , type );
423
426
if (!matchFound && isFactoryBean ) {
424
427
// In case of FactoryBean, try to match FactoryBean instance itself next.
425
428
beanName = FACTORY_BEAN_PREFIX + beanName ;
@@ -1091,7 +1094,7 @@ public Object doResolveDependency(DependencyDescriptor descriptor, String beanNa
1091
1094
Map <String , Object > matchingBeans = findAutowireCandidates (beanName , type , descriptor );
1092
1095
if (matchingBeans .isEmpty ()) {
1093
1096
if (descriptor .isRequired ()) {
1094
- raiseNoMatchingBeanFound (type , descriptor .getResolvableType (). toString () , descriptor );
1097
+ raiseNoMatchingBeanFound (type , descriptor .getResolvableType (), descriptor );
1095
1098
}
1096
1099
return null ;
1097
1100
}
@@ -1454,11 +1457,11 @@ private boolean isSelfReference(String beanName, String candidateName) {
1454
1457
* for an unresolvable dependency.
1455
1458
*/
1456
1459
private void raiseNoMatchingBeanFound (
1457
- Class <?> type , String dependencyDescription , DependencyDescriptor descriptor ) throws BeansException {
1460
+ Class <?> type , ResolvableType resolvableType , DependencyDescriptor descriptor ) throws BeansException {
1458
1461
1459
1462
checkBeanNotOfRequiredType (type , descriptor );
1460
1463
1461
- throw new NoSuchBeanDefinitionException (type , dependencyDescription ,
1464
+ throw new NoSuchBeanDefinitionException (resolvableType ,
1462
1465
"expected at least 1 bean which qualifies as autowire candidate. " +
1463
1466
"Dependency annotations: " + ObjectUtils .nullSafeToString (descriptor .getAnnotations ()));
1464
1467
}
0 commit comments