Answer the question
In order to leave comments, you need to log in
What is the difference between @Qualifier annotation and interface?
I'm reading the book Spring in action and the question arose why use qualifiers (in the book it shows on the example of string instruments), if you can simply implement the marker interface?
Interested in the pros and cons of the two methods, this is not described in the book.
Answer the question
In order to leave comments, you need to log in
`@Qualifier` allows you to make multiple implementations of the same interface.
A marker interface is not always an option. For example, if you need multiple database connections, then you need the `DataSource` interface for all of them. And to inherit from its implementations in order to add this very marker interface is not even always possible. For example, if the DataSource is implemented somewhere deep inside a connection pool or a JDBC driver.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question