wildfly部署ejb,访问时出错EJBCLIENT000025

发布于 2021-11-27 11:13:38 字数 7747 浏览 747 评论 1

我在ubuntu下有个wildfly。

先新建一个ejb项目,用eclipse部署wildfly上。

再写一个 java client访问ejb:出错

五月 29, 2014 2:48:41 下午 org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.0.0.Final
Obtained a remote stateless calculator for invocation
Adding 204 and 340 via the remote stateless calculator deployed on the server
Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:wildflyejb3, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@7ead510
	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:183)
	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.add(Unknown Source)
	at remoteClient.RemoteEJBClient.invokeStatelessBean(RemoteEJBClient.java:58)
	at remoteClient.RemoteEJBClient.main(RemoteEJBClient.java:27)
我的jboss-ejb-client.properties:

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=localhost
remote.connection.default.port = 8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
我的client代码是照着官网写的:
package remoteClient;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.imagin.stateful.CounterBean;
import com.imagin.stateful.RemoteCounter;
import com.imagin.stateless.CalculatorBean;
import com.imagin.stateless.RemoteCalculator;

public class RemoteEJBClient {

    
    public static void main(String[] args) throws Exception {
        
        invokeStatelessBean();
        invokeStatefulBean();
    }
 
    private static void invokeStatelessBean() throws NamingException {
        final RemoteCalculator statelessRemoteCalculator = lookupRemoteStatelessCalculator();
        System.out.println("Obtained a remote stateless calculator for invocation");
        int a = 204;
        int b = 340;
        System.out.println("Adding " + a + " and " + b + " via the remote stateless calculator deployed on the server");
        int sum = statelessRemoteCalculator.add(a, b);
        System.out.println("Remote calculator returned sum = " + sum);
        if (sum != a + b) {
            throw new RuntimeException("Remote stateless calculator returned an incorrect sum " + sum + " ,expected sum was " + (a + b));
        }
        int num1 = 3434;
        int num2 = 2332;
        System.out.println("Subtracting " + num2 + " from " + num1 + " via the remote stateless calculator deployed on the server");
        int difference = statelessRemoteCalculator.subtract(num1, num2);
        System.out.println("Remote calculator returned difference = " + difference);
        if (difference != num1 - num2) {
            throw new RuntimeException("Remote stateless calculator returned an incorrect difference " + difference + " ,expected difference was " + (num1 - num2));
        }
    }

    private static void invokeStatefulBean() throws NamingException {
        final RemoteCounter statefulRemoteCounter = lookupRemoteStatefulCounter();
        System.out.println("Obtained a remote stateful counter for invocation");
        System.out.println(statefulRemoteCounter.toString());
        final int NUM_TIMES = 20;
        System.out.println("Counter will now be incremented " + NUM_TIMES + " times");
        for (int i = 0; i < NUM_TIMES; i++) {
            System.out.println("Incrementing counter");
            statefulRemoteCounter.increment();
            System.out.println("Count after increment is " + statefulRemoteCounter.getCount());
        }
        System.out.println("Counter will now be decremented " + NUM_TIMES + " times");
        for (int i = NUM_TIMES; i > 0; i--) {
            System.out.println("Decrementing counter");
            statefulRemoteCounter.decrement();
            System.out.println("Count after decrement is " + statefulRemoteCounter.getCount());
        }
    }
    private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException {
        final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        final Context context = new InitialContext(jndiProperties);
        final String appName = "";
        final String moduleName = "wildflyejb3";
        final String distinctName = "";
        final String beanName = CalculatorBean.class.getSimpleName();
        final String viewClassName = RemoteCalculator.class.getName();
        return (RemoteCalculator) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
    }
    private static RemoteCounter lookupRemoteStatefulCounter() throws NamingException {
        final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        final Context context = new InitialContext(jndiProperties);
        final String appName = "";
        final String moduleName = "wildflyejb3";
        final String distinctName = "";
        final String beanName = CounterBean.class.getSimpleName();
        final String viewClassName = RemoteCounter.class.getName();
        return (RemoteCounter) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName + "?stateful");
    }
}
我的ejb部署log:

09:03:42,518 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean named CalculatorBean in deployment unit deployment "wildflyejb3.jar" are as follows:

	java:global/wildflyejb3/CalculatorBean!com.imagin.stateless.RemoteCalculator
	java:app/wildflyejb3/CalculatorBean!com.imagin.stateless.RemoteCalculator
	java:module/CalculatorBean!com.imagin.stateless.RemoteCalculator
	java:jboss/exported/wildflyejb3/CalculatorBean!com.imagin.stateless.RemoteCalculator
	java:global/wildflyejb3/CalculatorBean
	java:app/wildflyejb3/CalculatorBean
	java:module/CalculatorBean

09:03:42,519 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-2) JNDI bindings for session bean named CounterBean in deployment unit deployment "wildflyejb3.jar" are as follows:

	java:global/wildflyejb3/CounterBean!com.imagin.stateful.RemoteCounter
	java:app/wildflyejb3/CounterBean!com.imagin.stateful.RemoteCounter
	java:module/CounterBean!com.imagin.stateful.RemoteCounter
	java:jboss/exported/wildflyejb3/CounterBean!com.imagin.stateful.RemoteCounter
	java:global/wildflyejb3/CounterBean
	java:app/wildflyejb3/CounterBean
	java:module/CounterBean



各位 帮帮我吧。困我好久了

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

背叛残局 2021-11-28 16:26:01

remote.connection.default.host=localhost, 这个地址要和jboss部署配置standalone.xm中的发布地址要一致. 最好用IP地址!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文