Exception in thread "main" javax.naming.NameNotFoundException: ConnectionFactory.class 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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:589)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:669)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:694)
at java.lang.Thread.run(Thread.java:626)
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 cn.com.boyang.jboss.TopicSend.main(TopicSend.java:30)
程序源代码如下:
import javax.jms.*;
import javax.naming.*;
import java.util.Properties;
import java.io.*;/**
 * @author Administrator
 *
 */
public class TopicSend { /**
 * @param args
 */
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub TopicPublisher sender;
TextMessage msg;
Context ctx = null;
Properties p = new Properties();
FileInputStream f = new FileInputStream("jndi.properties");
p.load(f);
ctx = new InitialContext(p);
TopicConnectionFactory qConFactory = (TopicConnectionFactory)ctx.lookup("ConnectionFactory");
Topic topic = (Topic)ctx.lookup("topic/bitssub");
TopicConnection tCon = qConFactory.createTopicConnection();
TopicSession session = tCon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
sender = session.createPublisher(topic);
msg = session.createTextMessage();
msg.setText("Hello");
sender.send(msg);
}}