Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-17524

getBeanNamesForType(ResolvableType) doesn't work for raw singleton instance from @Bean method with generic return type

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 5.1.2
    • Fix Version/s: 4.3.21, 5.0.11, 5.1.3
    • Component/s: Core:DI
    • Labels:
      None

      Description

      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>\{ }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                vaxl Konstantin
                Last updater:
                Spring Issuemaster
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  14 weeks, 1 day ago