2017-05-09 128 views
0

我有一個JMS的基本示例: 這是發送消息的類。 我使用wildfly 10,我將它添加到STS。JMS Wildfly 10 - javax.naming.NameNotFoundException

package com.configuration; 

import java.util.Properties; 

import javax.jms.ConnectionFactory; 
import javax.jms.Destination; 
import javax.jms.JMSContext; 
import javax.naming.*; 

public class Config { 

    private static final String CONNECTION_FACTORY = "jms/ConnectionFactory"; 
    private static final String QUEUE_DESTINATION = "jms/testQueue"; 
    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory"; 
    private static final String PROVIDER_URL = "http-remoting://localhost:8080"; 

    public static void main (String[] args) throws NamingException{ 
     Context namingContext = null; 
     JMSContext context = null; 

     namingContext = getInitialContext(); 

     ConnectionFactory connectionFactory = (ConnectionFactory)namingContext.lookup(CONNECTION_FACTORY); 
     Destination destination = (Destination) namingContext.lookup(QUEUE_DESTINATION); 
     context = connectionFactory.createContext("viruskimera", "pmhjpmhj1"); 

     System.out.println("ENTERING JMS --- "); 
     context.createProducer().send(destination, "Hello message!!!"); 
     System.out.println("MESSAGE SENT --- "); 
     System.out.println("EXITING JMS --- "); 
    } 

    public static Context getInitialContext() throws NamingException{ 
     Context namingContext = null; 

     Properties props = new Properties(); 
     props.setProperty(Context.INITIAL_CONTEXT_FACTORY ,INITIAL_CONTEXT_FACTORY); 
     props.setProperty(Context.PROVIDER_URL, PROVIDER_URL); 
     props.setProperty(Context.SECURITY_PRINCIPAL, "user"); 
     props.setProperty(Context.SECURITY_CREDENTIALS, "password"); 
     props.put("jboss.naming.client.ejb.context", true); 

     namingContext = new InitialContext(props); 
     return namingContext; 
    } 

} 

這是我的堆棧跟蹤: 我試圖改變CONNECTION_FACTORY但不知道問題在那裏。 btw我將獨立版本更改爲完整版本。

may 08, 2017 6:30:30 PM org.xnio.Xnio <clinit> 
INFO: XNIO version 3.4.0.Final 
may 08, 2017 6:30:30 PM org.xnio.nio.NioXnio <clinit> 
INFO: XNIO NIO Implementation Version 3.4.0.Final 
may 08, 2017 6:30:30 PM org.jboss.remoting3.EndpointImpl <clinit> 
INFO: JBoss Remoting version 4.0.21.Final 
may 08, 2017 6:30:30 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage 
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river] 
may 08, 2017 6:30:30 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate 
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{[email protected], receiver=Remoting connection EJB receiver [connection=Remoting connection <6ad87bb3> on endpoint "config-based-naming-client-endpoint" <3108bc>,channel=jboss.ejb,nodename=viruskimera]} on channel Channel ID a2c74fcc (outbound) of Remoting connection 3701eaf6 to localhost/127.0.0.1:8080 of endpoint "config-based-naming-client-endpoint" <3108bc> 
Exception in thread "main" javax.naming.NameNotFoundException: jms/ConnectionFactory -- service jboss.naming.context.java.jboss.exported.jms.ConnectionFactory 
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106) 
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207) 
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184) 
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127) 
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

看起來像我失去了一些東西,我希望你的幫助。

回答