这个主要是调用同一项目中的会话 bean 将消息发送到单独项目中的消息驱动 bean。
另一个项目已完全部署并正常运行。
对于这个项目,可以部署会话 bean ejb。问题是当我尝试运行我的客户端主代码时,netbeans 可以部署代码但在运行它时给了我(警告:创建 ejb 对象的异常:[SSSbean])。我根本不明白为什么无法创建 ejb 对象。有任何想法吗?
会话 Bean 如下:
public class SSSbean implements SSSbeanRemote {
@Resource(name = "jms/Topic")
private static Topic topic;
@Resource(name = "jms/TopicConnectionFactory")
private static ConnectionFactory topicFactory;
public SSSbean () {}
@Override
public void createMessage(String messageData) throws JMSException {
Connection topicConnection = null;
Session session = null;
MessageProducer producer = null;
topicConnection = topicFactory.createConnection();
session = topicConnection.createSession(true,0);
topicConnection.start();
producer = session.createProducer(topic);
TextMessage tm = session.createTextMessage();
tm.setText(messageData);
producer.send(tm);
}
@Override
@Remove
public void remove() {
System.out.println("SSSBean:remove()");
}
}
主要内容如下:
public class Main {
@EJB
private static SSSbeanRemote ss;
public static void main(String[] args) {
// TODO code application logic here
Main client = new Main();
client.bX();
ss.remove();
}
private void bX() {
System.out.println("Main: Client started... ");
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Enter Suggestion: ");
String suggestion = sc.nextLine();
try{
ss.createMessage(suggestion);
continue;
} catch (JMSException j) {
System.out.println("Error: "+ j.toString());
}
}
}
}