2013-10-04 159 views
0

我一直在嘗試創建一個獨立的Java應用程序,它連接到JBOSS中的EJB作爲7.1.1。我正在閱讀本教程:https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDIJboss JNDI查找字符串

問題是,我只是無法連接到EJB。我總是遇到以下IllegalStateException:

Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:testeWeb-web-0.0.1-SNAPSHOT,modulename:testeWeb-ejb-0.0.1-SNAPSHOT,distinctname:] combination 
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:485) 
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:84) 
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175) 
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:122) 
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:107) 
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:90) 
at com.sun.proxy.$Proxy0.getSenha(Unknown Source) 
at testes.TesteCodigo.main(TesteCodigo.java:94) 

事情是。我不知道如何正確地形成JNDI查找字符串。這裏是我使用的loojup代碼 private static TesteFacade lookupFacade()throws NamingException最終Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES,「org.jboss.ejb.client.naming」);

final Context context = new InitialContext(jndiProperties); 

    return (TesteFacade) context.lookup("ejb:testeWeb-web-0.0.1-SNAPSHOT/testeWeb-ejb-0.0.1-SNAPSHOT//TesteFacadeImpl!facade.TesteFacade"); 
} 

,這裏是爲EJB部署日誌:

java:global/testeWeb/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl!facade.TesteFacade 
java:app/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl!facade.TesteFacade 
java:module/TesteFacadeImpl!facade.TesteFacade 
java:jboss/exported/testeWeb/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl!facade.TesteFacade 
java:global/testeWeb/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl 
java:app/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl 
java:module/TesteFacadeImpl 

我應該如何創建JNDI查找字符串?

+0

你部署.ear文件中的EJB? –

+0

看看JNDI網址,耳朵是存在的,它的名字是'testeWeb' – iskramac

回答

0

在你缺少EJB上下文初始化jndiProperties,嘗試那些道具:

Properties props = new Properties(); 
    props.put("jboss.naming.client.ejb.context", true); 
    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory"); 
    props.put(Context.PROVIDER_URL, "remote://localhost:4447"); 
    props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); 

我也認爲EJB URL不正確,嘗試查找您的EJB地址:

ejb:testeWeb/testeWeb-ejb-0.0.1-SNAPSHOT/TesteFacadeImpl!facade.TesteFacade