Error casting context.lookup(…) returned object to ejb3 remote object interface

会有一股神秘感。 提交于 2019-12-25 04:31:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!