【问题标题】:EJB 3 RemoteInterface class cast exception during lookup查找期间的 EJB 3 RemoteInterface 类转换异常
【发布时间】:2014-03-13 21:10:55
【问题描述】:

我正在使用 WebSphere Application Server 8.0.0.1。 我有两个企业应用程序在同一个 jvm 中运行(目前)。

我需要远程调用 EJB 方法

  1. 应用程序(“服务”) 接口:

    package myfirstpackage.ejb3;
    @Remote
    public interface TriggerManually {
        public boolean runTask(String taskName);
        public boolean resetTasks();
    }
    

    实施:

    package anotherpackage.ejb.remoteclient;
    @Stateless
    public class TriggerManuallyBean implements TriggerManually {
        @Override
        public boolean runTask(String taskName) {
            //Syso...
            return false;
        }
    
        @Override
        public boolean resetTasks() {
            //Syso...
            return false;
        }
    
    }
    
  2. 应用程序(“客户端”)使用服务(接口是共享的)

    public class TriggerManuallyClient {
      public void test() {
        Properties props = new Properties();
    
        props.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.ibm.websphere.naming.WsnInitialContextFactory");
        props.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost:2811");
    
        TriggerManually triggerManually;
        try {
            InitialContext ctx = new InitialContext(props);
            triggerManually = (TriggerManually) ctx
                    .lookup("myjdniname");
            triggerManually.resetTasks();
    
        } catch (NamingException e) {
            e.printStackTrace();
        }
      }
    }
    

但是我在查找过程中遇到了 Class Cast 异常:

Exception created : [java.lang.ClassCastException: myfirstpackage.ejb3._TriggerManually_Stub incompatible with anotherpackage.ejb.remoteclient.TriggerManually
    at anotherpackage.ejb.remoteclient.TriggerManuallyClient.test(TriggerManuallyClient.java:20)
    at com.ibm._jsp._status._jspService(_status.java:112)
    at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
    at com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper.handleRequest(GenericServletWrapper.java:122)
    at com.ibm.ws.jsp.webcontainerext.AbstractJSPExtensionServletWrapper.handleRequest(AbstractJSPExtensionServletWrapper.java:205)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:77)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:919)
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1016)
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:886)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1655)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)

我认为在 EJB 3 中我不必创建存根。我该如何解决我的问题?

【问题讨论】:

    标签: java ejb-3.0 remote-access classcastexception


    【解决方案1】:

    问题不在于通过查找返回的存根(是的,那些仍然存在于 EJB3 中)。

    仔细看ClassCastException

    myfirstpackage.ejb3._TriggerManually_Stub incompatible with anotherpackage.ejb.remoteclient.TriggerManually

    您可能在包anotherpackage.ejb.remoteclient 中也有一个TriggerManually 类。

    这可能会解决它:

    myfirstpackage.ejb3.TriggerManually triggerManually;
    try {
        InitialContext ctx = new InitialContext(props);
        triggerManually = (myfirstpackage.ejb3.TriggerManually) ctx.lookup("myjdniname");
        triggerManually.resetTasks();
    
    } catch (NamingException e) {
        e.printStackTrace();
    }
    

    【讨论】:

    • 非常感谢。我只是复制了界面,而是让两个耳朵文件使用相同的...
    【解决方案2】:

    在 Maven 中清理构建您的项目。

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    相关资源
    最近更新 更多