gpt4 book ai didi

java - EJB 远程客户端从 JBoss AS 7.1 迁移到 Wildfly 8.1

转载 作者:行者123 更新时间:2023-11-29 06:59:05 25 4
gpt4 key购买 nike

我们开发了一个培训应用程序,其中包含与 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 的文章(例如 thisthat )或 samplesWildfly Developer Guide ,但所有替代方案可能是最小的 JNDI 属性或通过 ClientContext 进行的扩展配置无法正常工作。

所以我的问题是,需要做些什么来迁移上面的代码/配置以在 WildFly 下运行它?

注意:这不是生产代码,因此安全性不是问题 - 如果我可以简化整个配置,那很好 - 它应该只演示如何从独立 Java 程序使用 EJB 远程接口(interface)。

最佳答案

你需要做两个改变

不要使用“remote://localhost:4447”,而是使用“http-remoting://localhost:8080”

jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");

在代码中配置 jndi 属性时,查找名称不应包含 ejb:

MyBeanRemote myBean = (MyBeanRemote) ctx.lookup("/training//MyBean!mypackage.MyBeanRemote");

这个解决方案已经过测试并且有效

关于java - EJB 远程客户端从 JBoss AS 7.1 迁移到 Wildfly 8.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29125023/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com