Check FactoryBean targetType for generic type as well
Closes gh-30987
This commit is contained in:
parent
34747baed0
commit
cba2b6eaf4
|
|
@ -908,6 +908,11 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||
// static factory method signature or from class inheritance hierarchy...
|
||||
return getTypeForFactoryBeanFromMethod(mbd.getBeanClass(), factoryMethodName);
|
||||
}
|
||||
|
||||
result = getFactoryBeanGeneric(mbd.targetType);
|
||||
if (result.resolve() != null) {
|
||||
return result;
|
||||
}
|
||||
result = getFactoryBeanGeneric(beanType);
|
||||
if (result.resolve() != null) {
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -1980,6 +1980,16 @@ class DefaultListableBeanFactoryTests {
|
|||
assertBeanNamesForType(FactoryBean.class, false, false);
|
||||
}
|
||||
|
||||
@Test // gh-30987
|
||||
void getBeanNamesForTypeWithFactoryBeanDefinedAsTargetType() {
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition(TestRepositoryFactoryBean.class);
|
||||
beanDefinition.setTargetType(ResolvableType.forClassWithGenerics(TestRepositoryFactoryBean.class,
|
||||
CityRepository.class, Object.class, Object.class));
|
||||
lbf.registerBeanDefinition("factoryBean", beanDefinition);
|
||||
assertBeanNamesForType(TestRepositoryFactoryBean.class, true, false, "&factoryBean");
|
||||
assertBeanNamesForType(CityRepository.class, true, false, "factoryBean");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a dependency on a {@link FactoryBean} can <strong>not</strong>
|
||||
* be autowired <em>by name</em>, as & is an illegal character in
|
||||
|
|
@ -3068,6 +3078,25 @@ class DefaultListableBeanFactoryTests {
|
|||
}
|
||||
|
||||
|
||||
public static class TestRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
|
||||
extends RepositoryFactoryBeanSupport<T, S, ID> {
|
||||
|
||||
@Override
|
||||
public T getObject() throws Exception {
|
||||
throw new IllegalArgumentException("Should not be called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
throw new IllegalArgumentException("Should not be called");
|
||||
}
|
||||
}
|
||||
|
||||
public record City(String name) {}
|
||||
|
||||
public static class CityRepository implements Repository<City, Long> {}
|
||||
|
||||
|
||||
public static class LazyInitFactory implements FactoryBean<Object> {
|
||||
|
||||
public boolean initialized = false;
|
||||
|
|
|
|||
Loading…
Reference in New Issue