基本的EJB3项目不起作用。 NameNotFound异常

时间:2014-11-02 13:29:11

标签: java jboss ejb wildfly

服务器端包含唯一的接口,bean @Remote@Stateless已注释。

已成功运行WildFly,我可以看到来自WildFly控制台的已部署bean。

它提示我uri JNDI绑定:

java:app/server_ejb/DeployBean!interfaces.Deploy

但我无法连接到此!

所以我的客户是:

初始上下文属性:

Context.INITIAL_CONTEXT_FACTORY=org.jboss.naming.remote.client.InitialContextFactory
Context.PROVIDER_URL=http-remoting://localhost:8080

客户端:

Properties props = new Properties(...);
InitialContext ctx = new InitialContext(props);
Deploy bean = (Deploy) ctx.lookup("java:app/server_ejb/DeployBean!interfaces.Deploy");
bean.sayHi();

我得到一个例外:

INFO: JBoss Remoting version (unknown)
Exception in thread "main" javax.naming.NameNotFoundException: app/server_ejb/DeployBean!interfaces.Deploy -- service jboss.naming.context.java.jboss.exported.app.server_ejb."DeployBean!interfaces.Deploy"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)

跆拳道? :(

1 个答案:

答案 0 :(得分:2)

在Wildfly中,为了远程访问EJB,可以使用 ejb:命名空间,语法如下:

对于无状态bean:

ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>

对于有状态bean:

ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>?stateful

另请参阅:EJB invocations from a remote client using JNDI