我需要编写一个无状态会话bean,我想将其部署到WLS 10.3.3。会话bean应该能够将文本消息发送到通过WLS控制台创建的已知JMS队列。因此我写了以下代码:
package com.mycompany.ejb;
import javax.annotation.Resource;
import javax.ejb.*;
import javax.jms.*;
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyEjb{
@Resource(name = "jmsConnectionFactory")
private ConnectionFactory jmsConnectionFactory;
@Resource(name = "queue1")
private Destination queue1;
public MyEjb(){}
public void sendMsgToQueue(String payload, ConnectionFactory connFactory, Destination destination) throws Exception{
if(payload == null)
throw new IllegalArgumentException("Message payload is null");
if(connFactory == null)
throw new IllegalArgumentException("Connection factory is null");
if(destination == null)
throw new IllegalArgumentException("Message destination is null");
Connection connection = connFactory.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer messageProducer = session.createProducer(destination);
TextMessage textMessage = session.createTextMessage();
textMessage.setText(payload);
messageProducer.send(textMessage);
}
}
我现在需要做的是提供一个有效的weblogic-ejb-jar.xml,其资源引用为jndi-name映射。有人可以提供weblogic-ejb-jar.xml的示例,其中包含以下映射: