Java Reference
In-Depth Information
public String messageBFactory(){
return "Another message";
You use these annotations to annotate the producer methods and their matching injection points as
shown in Listing 6-22.
LISTING 6‐22: Injecting the created beans using custom annotations to disambiguate
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.enterprise.event.Event;
import javax.inject.Inject;
public class EventService {
private String messageA;
private String messageB;
public void startService(){
System.out.println("Start service call " + messageA);
System.out.println("Start service call " + messageB);
A simpler approach would be to use the @Named annotation rather than creating your own
annotation type. This is implemented as in Listing 6‐23.
LISTING 6‐23: Using @Named annotations to disambiguate
package com.devchronicles.factory;
import javax.enterprise.inject.Produces;
public class EventProducer {
public String messageAFactory(){
Search WWH ::

Custom Search