I am using @ComponentScan
and @Component
to define my spring beans. What I would like is to declare one of these beans to be autowire-candidate=false
.
This could be done with this attribute in xml. Isn't there the equivalent in annotations?
The reason I want this is because I have 2 implementations of the same interface and I don't want to use @Qualifier
.
EDIT: Using @Primary is a valid work-around, but autowire-candidate seems to me like a useful feature with its own semantics.
Thanks
Looks like Spring refused autowire-candidate=false
concept and it no longer supported. There is no analogue with annotations, so @Primary
is the best work-around as you noticed.
Another way is to use custom org.springframework.beans.factory.support.AutowireCandidateResolver
, which is used in DefaultListableBeanFactory
, with logic that exclude undesirable beans from autowire candidates. In such case, the technology will be similar to that used for autowire-candidate=false
in SimpleAutowireCandidateResolver
.