幫我看看我的jmsBean,執行測試時出錯!

乖貓發表於2003-07-14
JMSBEANBean.java

package jms;

import javax.ejb.*;
import javax.jms.*;
import javax.naming.*;

public class JMSBEANBean implements MessageDrivenBean, MessageListener {
MessageDrivenContext messageDrivenContext;
public void ejbCreate() throws CreateException {
/**@todo Complete this method*/
}
public void ejbRemove() {
/**@todo Complete this method*/
}
public void onMessage(Message msg) {
try {
TextMessage TMS = (TextMessage) msg;
String a1 = TMS.getText();
String b1 = a1;
System.out.println("Message getted Is:" + a1 + "study" + b1 + ">>>>>>OK");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) {
this.messageDrivenContext = messageDrivenContext;
}
}


test.java

package jms;

import java.util.*;
import javax.jms.*;
import javax.naming.*;

public class test {
public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory";
public final static String URL="t3://127.0.0.1:7001";
private static final String QUEUE_CONNECTION_FACTORY="DemoJMSConnectionFactory";
private static final String QUEUE="DemoJMSQueue";
private static InitialContext getInitialContext(String url) throws NamingException{
Hashtable env=new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,JNDI_FACTORY);
env.put(Context.PROVIDER_URL,url);
return new InitialContext(env);
}

public static void main(String[] args) throws Exception{
Context ctx=getInitialContext(URL);
QueueConnectionFactory qConnFact=(QueueConnectionFactory)ctx.lookup(QUEUE_CONNECTION_FACTORY);
QueueConnection qConn=qConnFact.createQueueConnection();
QueueSession qSess=qConn.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
Queue q=(Queue)ctx.lookup(QUEUE);
QueueSender qSend=qSess.createSender(q);

TextMessage txtMsg=qSess.createTextMessage("c");
System.out.println("Sending a message to queue");
qSend.send(txtMsg);
txtMsg=qSess.createTextMessage("a");
System.out.println("Sending a message to queue");
qSend.send(txtMsg);
qConn.close();
System.exit(0);
}
}

weblogic中jms配置如下:
Connection Factories:JNDI NAME:DemoJMSConnectionFactory
Servers-DemoJMSServer-Destinations:DemoJMSQueue

執行測試程式時的錯誤提示:
javax.naming.NameNotFoundException: Unable to resolve 'DemoJMSQueue' Resolved: '' Unresolved:'DemoJMSQueue' ; remaining name 'DemoJMSQueue'

at weblogic.rmi.internal.BasicOutboundRequest.sendReceive(BasicOutboundRequest.java:109)

at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:263)

at weblogic.rmi.cluster.ReplicaAwareRemoteRef.invoke(ReplicaAwareRemoteRef.java:230)

at weblogic.jndi.internal.ServerNamingNode_WLStub.lookup(Unknown Source)

at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:337)

at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:332)

at javax.naming.InitialContext.lookup(InitialContext.java:347)

at jms.text.main(text.java:24)

Exception in thread "main"

也就是 Queue q=(Queue)ctx.lookup(QUEUE);出錯,可是我在weblogic上的名字確實是"DemoJMSQueue".

相關文章