发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 大数据 扩展性 并发编程 事件驱动 分布式 SOA

帮我看看我的jmsBean,运行测试时出错!

2003-07-14 11:34
赞助商链接

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".

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系管理员 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com