Spring @Autowiring, how to use factory object to select implementation?

I am trying to allow a runtime slice to decide which interface implementation should be used, preferably exclusively by auto-tuning.

I tried to make a factory object for thet interface that uses dynamic proxies, and I used qualifiers to force @Autowired injections to use factory. Qualifiers are necessary because both factory and implementations respond to the same interface.

The problem is that I am ending annotating each @Autowired link with @Qualifier. What I really would like to do is annotate non-factory implementations with something like @NotCandidateForAutowiringByInterface (my fantasy annotation) or even better make spring the preferred single unqualified bean when injected into an un- qualified field

I can think of completely wrong lines here, so alternative suggestions are welcome. Does anyone know how to do this?

0
java spring
source share
2 answers

You can use @Resource and specify a bean name factory.

+1
source share

I didn't look at it myself, but I noticed that Spring JavaConfig is turning into M4, and it seems to allow more flexibility with a combination of annotations and Java code. I wonder if this will offer a solution to your problem.

+1
source share

All Articles