2013-10-26 37 views
0

我已經嘗試並運行example以便將Remote訪問應用到客戶端的Bean中。它運行正常,但現在我想嘗試與Local Bean相同的過程。 Local接口的名稱現在是PersonalData,Bean實現類是Firstbean。更改創建查找名稱的方法:在使用JBoss的客戶端訪問本地Bean

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; 
       } 

,並試圖從主要作爲訪問豆:

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 [email protected] 
    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) 

如何使用Local使用Jboss訪問bean?

回答

2

如果我理解你的問題正確,你試圖通過他的本地接口使用遠程客戶端訪問Bean,這是不可能的。

在本地接口中聲明的服務僅適用於在Bean的同一應用程序中運行的客戶端。 Here你有一個更詳細的Bean的客戶必須滿足使用他的本地服務的屬性列表。

-1

仔細觀察遠程bean的bean名稱。

作爲一個例子,在WildFly中,檢索遠程bean的完整名稱包含「exported」 - 您可以從服務器的啓動日誌中找到實際名稱。