I'm a beginner with JEE (6), so I hope this question is not stupid. I have a stateless EJB which contains multiple JNDI Resources that should be injected:
@Stateless(name = "QueueDispatcher")
public class QueueDispatcher {
@Resource(name = "jms/syncQueue1")
private Queue queue1;
@Resource(name = "jms/syncQueue2")
private Queue queue2;
...
private List<Queue> queueList;
@PostConstruct
public void init() {
//Move injected queues into arraylist...
queueList = new ArrayList<Queue>();
if(queue1 != null){ queueList.add(queue1); }
if(queue2 != null){ queueList.add(queue2); }
...
}
}
My current implementation uses multiple fields to receive injected resources and then moves them into a Collection for subsequent use.
However, this code is ugly and the number of queues should be dynamic. When I have to increase the number of queues, I don't want to change the code on multiple places but instead simply add a single configuration line/annotation.
Is there a way configure stateless beans so that Resources are directly injected into the List? I'm using EJB 3.0.
Aucun commentaire:
Enregistrer un commentaire