晚上我在调message bean,用一个网上的视频教程,但是不知道哪里发生了错误,麻烦帮我看一下哈,谢谢哦.
这个是客户端的代码:package com.bjsxt.ejb;import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.InitialContext;import org.omg.CosCollection.QueueFactory;public class MyQueueBeanClient {

public static void main(String[] args) throws Exception{
InitialContext context =new InitialContext();

QueueConnectionFactory factory = (QueueConnectionFactory)context.lookup("ConnectionFactory");

QueueConnection connection = factory.createQueueConnection();

QueueSession session = connection.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);

Queue queue = (Queue)context.lookup("queue/myqueue");

TextMessage message = session.createTextMessage("世界你好");

QueueSender sender = session.createSender(queue);
}}
而这个是EJB的代码:package com.bjsxt.ejb;import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName="destinationType",propertyValue="Queue"),
@ActivationConfigProperty(propertyName="destination",propertyValue="queue/myqueue")
}
)public class MyQueueBean implements MessageListener{ public void onMessage(Message message) {
TextMessage text = (TextMessage)message;
try {
System.out.println("MyQueueBean"+"调用了"+"{"+text.getText()+"}");
} catch (JMSException e) {
e.printStackTrace();
}
}}
错误提示是:
Exception in thread "main" javax.naming.NameNotFoundException: myqueue not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
at org.jnp.server.NamingServer.lookup(NamingServer.java:270)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.bjsxt.ejb.MyQueueBeanClient.main(MyQueueBeanClient.java:25)