Jboss JNDI查找字符串

时间:2013-10-04 13:37:17

标签: java jboss ejb jndi

我一直在尝试创建一个独立的Java应用程序,它连接到JBOSS As 7.1.1中的EJB。我正在阅读本教程:https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+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()抛出NamingException {         final 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查找字符串?

1 个答案:

答案 0 :(得分:0)

在jndiProperties中,您缺少EJB上下文初始化,请尝试这些道具:

    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