This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

AnnouncementAnnouncement Module

Collapse

No announcement yet.

How to add Spring beans to a collection without method injection?Page Title Module

Now, I'd like to decouple this code from a particular implementation class (here aTypeImpl), but rather use Spring's factory for it.

I successfully got this to work with method injection and "aTypeImpl" being of scope "prototype", so I define an abstract "lookup" method in the class using the bean and let Spring dynamically implement it. Instead of a direct "new aTypeImpl()", I call this method and get my bean.

However, according to the documentation I found, I have to provide a lookup method in each class which uses the bean. I hate code duplication, but there are a couple of classes which need to instantiate my bean dynamically (again, I thought of the Factory pattern, but Spring already has/is one, so why implement another Factory of my own?).

Note I do not want to inject static collections given in the config file - this is pretty much clear to me. My topic is rather about dynamic collections.