Dec 19th, 2011, 01:11 PM
Auto-wire a set of beans?
not sure how newbie'ish or stupid this question seems, I haven't so far found a straightforward way of doing what I want so I'm back here. Basically, my structure is like this:
* I do have a given interface, say "IProviderStrategy", which is implemented a couple of times in my application. There is a client class keeping a "Set<IProviderStrategy> strategies", picking the "right" implementation and using it in a given situation.
* So far, I have a "setStrategies(Set<IProviderStrategy> ...)" setter in the client class, have all the various implementations of IProviderStrategy configured in my applicationContext and wired to the client class via setter injection and value-ref elements.
As I'd like to get rid of most of the XML configuration cluttering my setup, I'd like to use component-scan to find most of the IProviderStrategy implementations and then, in "some way", tell the application context to put all these implementations together in a Set and @Autowire this into the client class.
So to ask: Is this possible? Can something like this be done without too much ado, or is this beyond what one would like to do? Is there, as an alternative, a more "Spring" way to do what I want to do?
TIA, any input greatly appreciated!
Dec 19th, 2011, 03:00 PM
Please read the reference guide as this is explained in the reference guide. Section 4.9.2 explains this exact use case. Also use the search as this question has been answered numerous times before.