问题
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>
Have you any idea?
Thanks for your help
回答1:
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
And all required dependencies:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.2.0.Final</version>
<type>pom</type>
</dependency>
来源:https://stackoverflow.com/questions/36219951/error-casting-context-lookup-returned-object-to-ejb3-remote-object-interfac