Closed
Description
Konstantin opened SPR-17524 and commented
When calling beanFactory.getBeanNamesForType
with ResolvableType.forClassWithGenerics(), if bean is lazy it works, after initialization or bean not lazy this code will not work.
Here's a case, all asserts return true:
@SpringBootApplication
public class DemoApplication \{
public static void main(String[] args) {
ConfigurableApplicationContext run = SpringApplication.run(DemoApplication.class, args);
assert run.getBeanNamesForType(ResolvableType.forClassWithGenerics(Test.class, String.class)).length == 0;
assert run.getBean(run.getBeanNamesForType(ResolvableType.forClassWithGenerics(Test.class, Integer.class))[0]) != null;
assert run.getBeanNamesForType(ResolvableType.forClassWithGenerics(Test.class, Integer.class)).length == 0; }
@Bean
Test<String> getString() \{
return new Test<>();
}
@Bean
@Lazy
Test<Integer> getInteger() \{
return new Test<>();
} }
class Test<T>\{ }
Affects: 5.1.2
Issue Links:
- getBeanNamesForType(ResolvableType) does not reliably work for beans with AOP proxies [SPR-14097] #18669 getBeanNamesForType(ResolvableType) does not reliably work for beans with AOP proxies
- getBeanNamesForType(ResolvableType) doesn't match generic factory method return type for yet-to-be-created bean [SPR-15011] #19578 getBeanNamesForType(ResolvableType) doesn't match generic factory method return type for yet-to-be-created bean
Referenced from: pull request #2027, and commits ebbe14c, e9f7c35, 7b2eebe