Listing 12.8. Controlling instance being injected via a qualifier
In this listing you can see the qualifiers in action. You inject two User object instances.
In the first instance , you inject the seller of the item you're bidding on. In the second
case you inject the authenticated user who's doing the bidding . In both cases you've
provided additional information so that the CDI container can figure out which instance to
The example shows only one qualifier, but it's possible to use multiple qualifiers. Multiple
qualifiers provide an extra level of specification. Now that you have a handle on qualifiers,
let's take a look at disposers.
12.3.4. Disposer methods
A disposer method is responsible for handling the destruction of a bean. Although it's con-
ceptually similar to a C++ destructor or Java finalizer, it's uniquely different. First, a dis-
poser method is placed in the same class as the producer, not on the class being disposed.
Second, it's invoked when the context expires and the container is releasing the bean for
destruction. For example, if a bean is session-scoped, the disposer method will not be in-
voked until the session has timed out.
Implementing a disposer method involves adding the @Disposes annotation to a method
parameter. Qualifiers may also be used. Additional parameters can be specified; CDI will
attempt to resolve the additional parameters as beans using qualifiers if provided. When the