Define default implementation for injection in Spring?
I have a base class that is extended by some other classes. Therefore I have to provide qualifiers for being able to inject a specific instance.
I wonder if I could mark any of these classes (eg the most upper class) as default class, which would be picked up if no qualifier is provided on @Autowired?
@Service //@Qualifier("Parent") class ParentRunner; @Service @Qualifier("Child") class ChildRunner extends ParentRunner;
The following does at least not work:
@Autowired //@Qualifier("Parent") private ParentRunner runner;
You can mark one implementation with @Primary which will then be used as default. When using xml you can use the primary element inside the bean element to set an instance to the primary bean instance to use.