In real-world applications, it’s rare to have just one way of doing something. You might need to send a notification by email today, SMS tomorrow, and maybe push notifications next quarter. Sometimes you want the real service, sometimes a mock for testing. The interface stays the same, but suddenly you have multiple implementations competing for attention.
If you inject the interface directly, CDI has no idea which one to choose, and that’s where things get messy. You don’t want runtime guesswork or fragile string-based lookups that break during refactoring. What you need is a clean, type-safe mechanism to say: this injection point gets email, that one gets SMS.
That’s exactly what qualifiers give you. They’re CDI’s way of putting you in control of bean selection without sacrificing clarity or safety. In this tutorial, you’ll build a simple notification system with two implementations, email and SMS, and see how qualifiers let you choose your fighter at injection time. Along the way, you’ll pick up patterns that scale far beyond messaging, into areas like cloud integrations, test doubles, and modular service architectures.
The original article published on My Substack https://www.the-main-thread.com/p/quarkus-cdi-qualifier-multiple-implementations
Head over to read the full piece!
Top comments (0)