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


      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 {
        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.


          Issue Links



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


                • Created:
                  Days since last comment:
                  1 year, 1 week, 5 days ago