Spring @Autowiring, how to use an object factory to choose implementation?


Spring @Autowiring, how to use an object factory to choose implementation?



I am trying to let a piece of runtime state decide WHICH implementation of an interface to use, preferably solely by autowiring.

I have tried making an object factory for the interface thet uses dynamic proxies, and I used qualifiers to coerce the @Autowired injections to use the factory. The qualifiers are necessary because both the factory and the implementations respond to the same interface.

The problem with this is that I end up annotating every @Autowired reference with the @Qualifier. What I'd really want to do is annotate the non-factory implementations with something like @NotCandidateForAutowiringByInterface (my fantasy annotation), or even better make spring prefer the single un-qualified bean when injecting to an un-qualified field

I may thinking along the totally wrong lines here, so alternate suggestions are welcome. Anyone know how to make this happen ?




How can I have previous value of checkbox in Spring?

1:



How do I setQueryTimeout on SimpleJdbcTemplate?
You could use @Resource and specify the bean name of the factory..
Relative References in Expressions in XML bean definitions in Spring 3.0


Spring ApplicationContext Bean Scope


Receiving an array of Object from a web form using Spring framework

2:



Eclipse keeps changing the Targeted Runtimes
I haven't looked at this myself but I noticed Spring JavaConfig is made it to M4 and it seems to allow more flexible configuration through a combination of annotations and Java code.


How to use Spring to inject an object in a setter that doesnt follow the Java bean specification?
I wonder if it would offer a solution to your problem..
Bulk inserts with Spring / Hibernate



88 out of 100 based on 58 user ratings 958 reviews

*