Is there a way in Spring that I can auto populate a list with all of beans of a type AND any of its subtypes? I have a setter method that looks like:
setMyProp(List<MyType> list)
And I would like to autowire in any beans of MyType and all subclasses of MyType.
Thanks,
Jeff
Yup, you can do this. The spring docs say:
Note that it says you need to expect an array, not a list. This makes sense, because generic type erasure means a list may not work at runtime. However, take the following unit test, which works:
and this unit test:
So officially, you’re supposed to autowire
TypeA[], notList<TypeA>, but the List works good.