【问题标题】:Error casting context.lookup(...) returned object to ejb3 remote object interface将 context.lookup(...) 返回的对象转换为 ejb3 远程对象接口时出错
【发布时间】:2016-03-25 12:28:58
【问题描述】:

我有一个在 JBoss 服务器下运行的无状态 EJB 和在另一个 JBoss 服务器下运行的客户端。

在客户端,我使用以下代码:

final Properties initialContextProperties = new Properties();
initialContextProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
initialContextProperties.put(Context.PROVIDER_URL, "remote://127.0.0.1:8083");
initialContextProperties.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
initialContextProperties.put("jboss.naming.client.ejb.context", true);

final InitialContext contexte = new InitialContext(initialContextProperties);
Object remoteObj = contexte.lookup("ejb:my-web-app/MyEjbRemoteImpl!my.ejb.remote.MyEjbRemoteInterface");
MyEjbRemoteInterface myEjb = (my.ejb.remote.MyEjbRemoteInterface) remoteObj;

在运行这段代码时,我遇到了这个异常:

org.jboss.ejb.client.naming.ejb.EjbNamingContext cannot be cast to my.ejb.remote.MyEjbRemoteInterface

这些依赖在客户端的类路径中:

<dependency>
    <groupId>org.jboss</groupId>
    <artifactId>jboss-remote-naming</artifactId>
    <version>2.0.4.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.xnio</groupId>
    <artifactId>xnio-nio</artifactId>
    <version>3.3.6.Final</version>
</dependency>

你有什么想法吗?

感谢您的帮助

【问题讨论】:

  • 正如 JBoss 文档的 Pre-requisites of remotely accessible JNDI objects 部分所述,使用远程命名项目时使用的 JNDI 名称始终与 java:jboss/exported/ 相关。 b> 命名空间。因此,您应该从查找字符串中删除 ejb:

标签: java jndi ejb-3.0 jboss6.x


【解决方案1】:

问题出在查找方法字符串参数中。它必须像:ejb:/my-web-app//MyEjbRemoteImpl!my.ejb.remote.MyEjbRemoteInterface。一般喜欢ejb:AppName/EjbModuleName/DistinctName/EjbRemoteBeanImpName!ejb.remote.interface.Name

以及所有必需的依赖项:

    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-ejb-client-bom</artifactId>
        <version>7.2.0.Final</version>
        <type>pom</type>
    </dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-29
    • 2021-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多