0
的集合属性我有一个无状态EJB包含多个JNDI资源应该被注入:进样JNDI资源投入到EJB
@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); }
...
}
}
我的当前实现使用多个字段接收注入资源,然后将它们移动到一个收集以备后用。
但是,这段代码很丑,队列数量应该是动态的。当我不得不增加队列数量时,我不想在多个地方更改代码,而只需添加一个配置行/注释。
有没有办法配置无状态bean,以便资源直接注入到列表中?我正在使用EJB 3.0。
这看起来像我需要的exacly,谢谢:) – maja