From edb8a052c3be257f9fb5813aae9b7defbb9d5a35 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 3 Aug 2023 12:43:23 +0200 Subject: [PATCH] Add test case See gh-30987 --- .../DefaultListableBeanFactoryTests.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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 {