Java EE 7和Wildfly 10.1.0 - IllegalStateException:EJBCLIENT000025

时间:2017-04-06 14:07:39

标签: ejb wildfly jndi java-ee-7

我创建了以下EJB-Module:
1)我的远程接口

package calculator.beans;
import javax.ejb.Remote;

@Remote
public interface CalculatorRemote {
    public int addNum(int num1, int num2);
}


2)实现接口的bean

package calculator.beans;
import javax.ejb.Stateless;

@Stateless
public class CalculatorBean implements CalculatorRemote {

    @Override
    public int addNum(int num1, int num2) {
        return num1 + num2;
    }
}


3)接下来我创建了一个属性文件' jboss-ejb-client.properties '

endpoint.name=client-endpoint
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default
remote.connection.default.host=127.0.0.1
remote.connection.default.port = 8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

remote.connection.default.username=appuser
remote.connection.default.password=apppassword


部署到wildfly之后一切都很好。我得到以下信息:

INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-4) WFLYEJB0473: JNDI bindings for session bean named 'CalculatorBean' in deployment unit 'deployment "CalculatorEJB.jar"' are as follows:

    java:global/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
    java:app/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
    java:module/CalculatorBean!calculator.beans.CalculatorRemote
    java:jboss/exported/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
    java:global/CalculatorEJB/CalculatorBean
    java:app/CalculatorEJB/CalculatorBean
    java:module/CalculatorBean

4)然后我创建了我的Java客户端

package calculator.client;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import calculator.beans.CalculatorRemote;

public class RemoteRechnerClient {

    public static void main(String[] args) {
        try {
            final Hashtable<String, String> jndiProperties = new Hashtable<>();
            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
            final Context ctx = new InitialContext(jndiProperties);
            String crName = CalculatorRemote.class.getName();
            CalculatorRemote cr = (CalculatorRemote) ctx.lookup("ejb:CalculatorEJB/beans/CalculatorBean!" + crName);

            System.out.println("Result: " + cr.addNum(5, 4));

        } catch (NamingException ex) {
            ex.printStackTrace();
        }
    }
}

代码很简单。但是,如果我运行客户端,我会收到错误消息:

Apr 06, 2017 3:30:26 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.0.1.Final
Apr 06, 2017 3:30:26 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.0.Final
Apr 06, 2017 3:30:26 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.0.Final
Apr 06, 2017 3:30:26 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.6.Final
Apr 06, 2017 3:30:27 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
Apr 06, 2017 3:30:27 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3c0f93f1, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@31dc339b,channel=jboss.ejb,nodename=john-waynes-macbook-pro]} on channel Channel ID b98547a5 (outbound) of Remoting connection 0c84e8ba to /127.0.0.1:8080
Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:CalculatorEJB, moduleName:beans, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@2758fe70
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
    at com.sun.proxy.$Proxy0.addNum(Unknown Source)
    at calculator.client.RemoteRechnerClient.main(RemoteRechnerClient.java:27)
/Users/manhthangd/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 3 seconds)

我正在使用Netbeans 8.2,Java EE 7和Wildfly 10.1.0-Final。 我该怎么做才能解决问题?

1 个答案:

答案 0 :(得分:0)

您的JNDI查找名称不正确。

您需要使用突出显示的部分:

  

的java:JBoss的/导出/ <强> CalculatorEJB / CalculatorBean calculator.beans.CalculatorRemote

CalculatorRemote cr = (CalculatorRemote) ctx.lookup("ejb:CalculatorEJB/CalculatorBean!" + crName);

你从哪里得到"ejb:CalculatorEJB/beans/CalculatorBean!"