diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
index 7f7ab566852d..461478c3c58a 100644
--- a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
+++ b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java
@@ -2032,6 +2032,16 @@ void getBeanNamesForTypeWithPrototypeScopedFactoryBean() {
assertBeanNamesForType(FactoryBean.class, false, false);
}
+ @Test // gh-xxxx
+ 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 not
* be autowired by name, as & is an illegal character in
@@ -3119,6 +3129,24 @@ public T call() {
}
}
+ public static class TestRepositoryFactoryBean, S, ID extends Serializable>
+ extends RepositoryFactoryBeanSupport {
+
+
+ @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 {}
public static class LazyInitFactory implements FactoryBean