Check FactoryBean targetType for generic type as well
Closes gh-30987
This commit is contained in:
@@ -908,6 +908,11 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
|||||||
// static factory method signature or from class inheritance hierarchy...
|
// static factory method signature or from class inheritance hierarchy...
|
||||||
return getTypeForFactoryBeanFromMethod(mbd.getBeanClass(), factoryMethodName);
|
return getTypeForFactoryBeanFromMethod(mbd.getBeanClass(), factoryMethodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = getFactoryBeanGeneric(mbd.targetType);
|
||||||
|
if (result.resolve() != null) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
result = getFactoryBeanGeneric(beanType);
|
result = getFactoryBeanGeneric(beanType);
|
||||||
if (result.resolve() != null) {
|
if (result.resolve() != null) {
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1980,6 +1980,16 @@ class DefaultListableBeanFactoryTests {
|
|||||||
assertBeanNamesForType(FactoryBean.class, false, false);
|
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>
|
* Verifies that a dependency on a {@link FactoryBean} can <strong>not</strong>
|
||||||
* be autowired <em>by name</em>, as & is an illegal character in
|
* 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 static class LazyInitFactory implements FactoryBean<Object> {
|
||||||
|
|
||||||
public boolean initialized = false;
|
public boolean initialized = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user