Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 4.0 RC1
    • Component/s: None
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      Currently the container considers List and Map types being injected as special injection points and uses generics inspection to inject the appropriate Spring beans. However, there's no general support for injecting generic types in a type safe way.

      Assuming we have a generic interface:

      interface MyGenericType<T> { ... }
      

      and two Spring beans:

      class IntegerType extends MyGenericType<Integer> { ... }
      
      class StringType extends MyGenericType<String> { ... }
      

      A client trying to get a special instance of the generic type looking like this:

      class MyClient {
      
        @Autowired
        private List<MyGenericType<Integer>> dependencies;
      }
      

      currently not only gets injected the IntegerType bean but the StringType as well which will cause exceptions at runtime. The core reason this is the case is that the BeanFactory currently uses Class<?> based type information that does not carry the generics information on injection time and selectvely inspects the generics for injection of special types like List and Map.

      The Spring Data Commons project has a TypeInformation abstraction that allows to lazily resolve generics information as it keeps the generics information around when traversing types, property, method parameter and method return types. It could serve as foundation for an improvement of the BeanFactory.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                olivergierke Oliver Drotbohm
                Last updater:
                Spring Issuemaster
              • Votes:
                5 Vote for this issue
                Watchers:
                13 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  39 weeks, 4 days ago