You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JBoss EAP 6.4远程RMI调用失败求助:javax.naming.NameNotFoundException问题排查

问题分析与解决方案

看起来你在JBoss EAP 6.4上远程调用EJB时踩了几个常见的版本兼容和JNDI格式的坑,我帮你梳理下问题和解决办法:

1. 客户端依赖版本不匹配

你当前使用的wildfly-naming-client是WildFly服务器的客户端库,但你的目标服务器是JBoss EAP 6.4——这两个版本的客户端API不兼容,这是导致命名查找失败的核心原因之一。

你需要替换成JBoss EAP 6.4对应的官方客户端依赖,修改你的pom.xml:

<dependencies>
    <!-- 导入JBoss EAP 6.4 EJB客户端BOM,统一依赖版本 -->
    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-ejb-client-bom</artifactId>
        <version>6.4.0.Final</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
    <!-- 核心EJB客户端依赖 -->
    <dependency>
        <groupId>org.jboss.ejb-client</groupId>
        <artifactId>jboss-ejb-client</artifactId>
    </dependency>
    <!-- 远程命名支持 -->
    <dependency>
        <groupId>org.jboss.remote-naming</groupId>
        <artifactId>jboss-remote-naming</artifactId>
    </dependency>
    <!-- XNIO传输依赖 -->
    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.jboss.xnio</groupId>
        <artifactId>xnio-nio</artifactId>
    </dependency>
    <!-- 你的远程接口依赖,保持不变 -->
    <dependency>
        <groupId>se.testcompany.testapplication</groupId>
        <artifactId>rmi-interface</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

2. 远程JNDI名称使用错误

服务器日志里的java:global/...是JBoss内部的命名空间,远程客户端无法直接访问这个前缀。在JBoss EAP 6.x中,远程调用EJB需要使用特定的ejb:前缀格式:

ejb:<ear名称>/<模块名称>/<Bean类名>!<远程接口全限定名>

对应你的场景,正确的JNDI名称应该是:

String jndiName = "ejb:app-0.0.1-SNAPSHOT/se.testcompany.testapplication-server-0.0.1-SNAPSHOT/JournalCrudFacadeBean!se.testcompany.testapplication.rmi_interface.JournalCrudRemoteInterface";

3. 补充关键的JNDI配置属性

你需要在初始上下文的属性中添加一个参数,让客户端能够正确识别EJB的远程命名格式:

jndiProperties.put("jboss.naming.client.ejb.context", "true");

另外,确保你保留了JBoss EAP 6.x对应的初始上下文工厂(不要换成WildFly的那个):

jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

修正后的完整调用代码

private String create() {
    String id = "Inget svar";
    try {
        final Hashtable<String, String> jndiProperties = new Hashtable<String, String>();
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        jndiProperties.put(Context.PROVIDER_URL, "remoting://localhost:4447");
        // 启用EJB远程上下文支持,必须添加
        jndiProperties.put("jboss.naming.client.ejb.context", "true");
        jndiProperties.put("remote.connection.default.username", "testapplication");
        jndiProperties.put("remote.connection.default.password", "!234qwer");
        
        final InitialContext ctx = new InitialContext(jndiProperties);
        // 使用正确的远程JNDI名称
        String jndiName = "ejb:app-0.0.1-SNAPSHOT/se.testcompany.testapplication-server-0.0.1-SNAPSHOT/JournalCrudFacadeBean!se.testcompany.testapplication.rmi_interface.JournalCrudRemoteInterface";
        JournalCrudRemoteInterface journalCrudRemoteInterface = (JournalCrudRemoteInterface) ctx.lookup(jndiName);
        
        id = journalCrudRemoteInterface.create(new Date());
        System.out.println(id);
    } catch (Exception e) {
        id = e.getClass().getName() + " " + e.getMessage();
        e.printStackTrace();
    }
    return id;
}

额外检查项

  • 确认你的远程接口JournalCrudRemoteInterface在客户端和服务器端的包名、方法签名完全一致(包括必须抛出RemoteException)。
  • 检查JBoss EAP 6.4的standalone-full.xml中,remoting-connector是否已启用(默认端口4447,你当前配置的是对的)。
  • 确保你创建的testapplication用户拥有ejb相关权限:在执行add-user.sh/add-user.bat时选择Application User,并为其分配jboss-ejb-client角色。

内容的提问来源于stack exchange,提问作者user2902165

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 21:02:28