parent
0ce9516aef
commit
eeac150030
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -585,8 +585,9 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
|||
if (!matchFound) {
|
||||
// In case of FactoryBean, try to match FactoryBean instance itself next.
|
||||
beanName = FACTORY_BEAN_PREFIX + beanName;
|
||||
matchFound = (includeNonSingletons || isSingleton(beanName, mbd, dbd)) && isTypeMatch(beanName, type, allowFactoryBeanInit);
|
||||
|
||||
if (includeNonSingletons || isSingleton(beanName, mbd, dbd)) {
|
||||
matchFound = isTypeMatch(beanName, type, allowFactoryBeanInit);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matchFound) {
|
||||
|
|
|
@ -1859,6 +1859,22 @@ class DefaultListableBeanFactoryTests {
|
|||
assertBeanNamesForType(FactoryBean.class, false, false, "&factoryBean");
|
||||
}
|
||||
|
||||
@Test // gh-28616
|
||||
void getBeanNamesForTypeWithPrototypeScopedFactoryBean() {
|
||||
FactoryBeanThatShouldntBeCalled.instantiated = false;
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class);
|
||||
beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||
lbf.registerBeanDefinition("factoryBean", beanDefinition);
|
||||
assertThat(FactoryBeanThatShouldntBeCalled.instantiated).isFalse();
|
||||
assertThat(lbf.containsSingleton("factoryBean")).isFalse();
|
||||
|
||||
// We should not find any beans of the following types if the FactoryBean itself is prototype-scoped.
|
||||
assertBeanNamesForType(Runnable.class, false, false);
|
||||
assertBeanNamesForType(Callable.class, false, false);
|
||||
assertBeanNamesForType(RepositoryFactoryInformation.class, false, false);
|
||||
assertBeanNamesForType(FactoryBean.class, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a dependency on a {@link FactoryBean} can <strong>not</strong>
|
||||
* be autowired <em>by name</em>, as & is an illegal character in
|
||||
|
|
Loading…
Reference in New Issue