JMS Wildfly 10 - javax.naming.NameNotFoundException

时间:2017-05-09 00:02:52

标签: java jms wildfly-10

我有一个JMS的基本示例: 这是发送消息的类。 我使用wildfly 10,我把它添加到STS。

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但不确定问题是否存在。 顺便说一下,我将独立版改为完整版。

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{clientContext=org.jboss.ejb.client.EJBClientContext@13a5fe33, 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)

看起来我错过了什么,我很感激你的帮助。

1 个答案:

答案 0 :(得分:1)

我不知道您是否找到了答案,但是您需要配置邮件系统,默认情况下没有配置,默认邮件配置条目仅存在于standalone-full.xml和standalone-full-ha上。 XML。正如您在此处所见:https://docs.jboss.org/author/display/WFLY10/Messaging+configuration