【发布时间】: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