将context.lookup(...)返回的对象强制转换为ejb3远程对象接口时出错 [英] Error casting context.lookup(...) returned object to ejb3 remote object interface
问题描述
我有一个在JBoss服务器下运行的EJB无状态,而一个客户机在另一个JBoss服务器下运行。
I have an EJB stateless running under a JBoss server and a client under another JBoss server.
在客户端,我使用以下代码:
In the client side, I am using the following code:
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;
在运行此代码时,我有一个例外:
While running this code, I have this exception:
org.jboss.ejb.client.naming.ejb.EjbNamingContext cannot be cast to my.ejb.remote.MyEjbRemoteInterface
这些依赖项在客户端的类路径中:
These dependencies are in the classpath of the client side:
<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>
您有任何想法吗?
谢谢为您提供帮助
推荐答案
问题出在查找方法字符串参数中。它必须类似于: ejb:/ my-web-app // MyEjbRemoteImpl!my.ejb.remote.MyEjbRemoteInterface
。通常类似于 ejb:AppName / EjbModuleName / DistinctName / EjbRemoteBeanImpName!ejb.remote.interface.Name
The problem was in the lookup method string parameter. It must be like: ejb:/my-web-app//MyEjbRemoteImpl!my.ejb.remote.MyEjbRemoteInterface
. Generally like 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>
这篇关于将context.lookup(...)返回的对象强制转换为ejb3远程对象接口时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!