0

我已经尝试并运行该示例,以便在客户端中应用Remote对 Bean 的访问。它运行正常,但现在我想用LocalBean 尝试相同的过程。Local 接口的名称现在是 PersonalData,bean 实现类是 Firstbean. 将创建查找名称的方法更改为:

private static String getLookupLocalName() {
            /*
            The app name is the EAR name of the deployed EJB without .ear suffix.
            Since we haven't deployed the application as a .ear,
            the app name for us will be an empty string
            */
                    String appName = "";

                    /* The module name is the JAR name of the deployed EJB
                    without the .jar suffix.
                    */
                    String moduleName = "EJBTest";

            /*AS7 allows each deployment to have an (optional) distinct name.
            This can be an empty string if distinct name is not specified.
            */
                    String distinctName = "";

                    // The EJB bean implementation class name
                    String beanName = FirstBean.class.getSimpleName();

                    // Fully qualified remote interface name
                    final String interfaceName = PersonalData.class.getName();

                    // Create a look up string name
                    String name = "ejb:" + appName + "/" + moduleName + "/" +
                        distinctName    + "/" + beanName + "!" + interfaceName;

                    return name;
                }

并尝试从 main 访问 Bean:

public static void main(String[] args) {

    PersonalData bean = doLookup(getLookupLocalName());
    System.out.println(bean.getName()); 

    }

它抛出一个NoSuchEJBException

   javax.ejb.NoSuchEJBException: No such EJB[appname=,modulename=EJBTest,distinctname=,beanname=FirstBean,viewclassname=com.al.ejbtest.PersonalData]
    at org.jboss.ejb.client.remoting.NoSuchEJBExceptionResponseHandler.processMessage(NoSuchEJBExceptionResponseHandler.java:64)
    at org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver.handleMessage(ChannelAssociation.java:395)
    at org.jboss.remoting3.remote.RemoteConnectionChannel$5.run(RemoteConnectionChannel.java:437)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:EJBTest,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@67a524a7
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
    at org.jboss.ejb.client.EJBClientInvocationContext.retryRequest(EJBClientInvocationContext.java:206)
    at org.jboss.ejb.client.EJBReceiverInvocationContext.retryInvocation(EJBReceiverInvocationContext.java:95)
    at org.jboss.ejb.client.remoting.NoSuchEJBExceptionResponseHandler.processMessage(NoSuchEJBExceptionResponseHandler.java:78)
    at org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver.handleMessage(ChannelAssociation.java:395)
    at org.jboss.remoting3.remote.RemoteConnectionChannel$5.run(RemoteConnectionChannel.java:437)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
    at ...asynchronous invocation...(Unknown Source)
    at org.jboss.ejb.client.remoting.NoSuchEJBExceptionResponseHandler$ResultProducer.getResult(NoSuchEJBExceptionResponseHandler.java:101)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:270)
    at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:47)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:272)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocationResult(ReceiverInterceptor.java:132)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:260)
    at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:399)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:140)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
    at com.sun.proxy.$Proxy0.getName(Unknown Source)
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:20)

如何使用LocalJboss 访问 bean?

4

2 回答 2

2

如果我理解您的问题是正确的,您正在尝试使用远程客户端通过他的本地接口访问 Bean,这是不可能的。

在 Local 接口中声明的服务仅对在 Bean 的同一应用程序中运行的客户端可用。在这里,您可以更详细地列出 Bean 的客户端必须满足哪些属性才能使用其本地服务。

于 2013-10-27T15:18:45.467 回答
-1

仔细观察远程 bean 的 bean 名称。

例如,在 WildFly 中,检索远程 bean 的完整名称包含“exported”——您可以从服务器的启动日志中发现实际名称。

于 2018-02-09T09:59:08.367 回答