Perform type check before singleton check for early FactoryBean matching

Closes gh-34710
This commit is contained in:
Juergen Hoeller
2025-04-03 11:59:22 +02:00
parent 8f9cbcd86d
commit e7db15b325
2 changed files with 33 additions and 2 deletions

View File

@@ -639,10 +639,15 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
}
else {
if (includeNonSingletons || isNonLazyDecorated ||
(allowFactoryBeanInit && isSingleton(beanName, mbd, dbd))) {
if (includeNonSingletons || isNonLazyDecorated) {
matchFound = isTypeMatch(beanName, type, allowFactoryBeanInit);
}
else if (allowFactoryBeanInit) {
// Type check before singleton check, avoiding FactoryBean instantiation
// for early FactoryBean.isSingleton() calls on non-matching beans.
matchFound = isTypeMatch(beanName, type, allowFactoryBeanInit) &&
isSingleton(beanName, mbd, dbd);
}
if (!matchFound) {
// In case of FactoryBean, try to match FactoryBean instance itself next.
beanName = FACTORY_BEAN_PREFIX + beanName;