【发布时间】:2015-05-21 09:53:45
【问题描述】:
我们开发了一个培训应用程序,其中包含一个与 EJB 通信的独立 Java 客户端。工作设置包括 Windows 7 上的 JBoss AS 7.1 和通过 /bin/add-user.bat 创建的应用程序用户。
客户端是这样编码的:
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put("jboss.naming.client.ejb.context", true);
jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447");
jndiProps.put(Context.SECURITY_PRINCIPAL, "user");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxx");
Context ctx = new InitialContext(jndiProps);
MyBeanRemote myBean = (MyBeanRemote) ctx.lookup("ejb:/training//MyBean!mypackage.MyBeanRemote");
String result = myBean.greet("John");
客户端是用类路径中的 jboss-client.jar 启动的。
现在我们尝试使用成功部署的 WildFly 8.1,但客户端失败
Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:syjeews, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@6e7d3146
将 JNDI 查找名称更改为在部署期间打印出来的名称(例如 java:global/training/MyBean!mypackage.MyBeanRemote)导致
Exception in thread "main" javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [remote://localhost:4447 (java.net.ConnectException: Connection refused: no further information)]
在谷歌上搜索了一段时间后,我们偶然发现了几篇关于 SO(例如 this 或 that)或 samples 或 Wildfly Developer Guide 的文章,但所有替代方案,可能是最小的 JNDI 属性或扩展的通过 ClientContext 配置并没有使其工作。
所以我的问题是,需要做些什么来迁移上面的代码/配置以在 WildFly 下运行它?
注意:这不是生产代码,因此安全性不是问题 - 如果我可以简化整个配置,那很好 - 它应该只演示如何从独立的 Java 程序使用 EJB 远程接口。
【问题讨论】:
标签: java jakarta-ee ejb jboss7.x wildfly