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.
See http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Primary.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With