当前位置: 首页 > 知识库问答 >
问题:

为什么我在Wildfly8.2.1中访问EJB2.1时会得到ClassCastException?

苏昊英
2023-03-14
    null

在P001_EJB中,我创建了一个XDoclet无状态会话Bean(EJB2.1)。

这是它的远程界面:

package com.p001.ejb;

/**
 * Remote interface for Test1SLB.
 * @generated 
 * @wtp generated
 */
public interface Test1SLB extends javax.ejb.EJBObject
{
   /**
    * <!-- begin-xdoclet-definition -->
    * @generated //TODO: Must provide implementation for bean method stub    */
   public java.lang.String foo( java.lang.String param )
      throws java.rmi.RemoteException;    
}

这是它的主界面:

package com.p001.ejb;

/**
 * Home interface for Test1SLB.
 * @generated 
 * @wtp generated
 */
public interface Test1SLBHome extends javax.ejb.EJBHome
{
   public static final String COMP_NAME="java:comp/env/ejb/Test1SLB";
   public static final String JNDI_NAME="Test1SLB";

   public com.p001.ejb.Test1SLB create()
      throws html" target="_blank">javax.ejb.CreateException,java.rmi.RemoteException;
}
public class P001Listener implements ServletContextListener {

    public P001Listener() {
    }

    public void contextInitialized(ServletContextEvent sce)  { 
         System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): inside");
         String test1SLBJNDIName = null;
         Class test1SLBHomeClass = null;
         InitialContext initialContext = null;
         Object namedObject = null;
         Object ejbHomeObject = null;
         Test1SLBHome test1SLBHome = null;
         Test1SLB test1SLB = null;
         String rtnValue = null;


         try {

            test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB";
            System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): test1SLBJNDIName=" + test1SLBJNDIName);

            test1SLBHomeClass = Test1SLBHome.class;
            System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): test1SLBHomeClass=" + test1SLBHomeClass);

            initialContext = new InitialContext();
            System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): initialContext=" + initialContext);

            namedObject = initialContext.lookup(test1SLBJNDIName);
            System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): namedObject=" + namedObject);

            ejbHomeObject = PortableRemoteObject.narrow(namedObject, test1SLBHomeClass);
            System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): ejbHomeObject=" + ejbHomeObject);

            test1SLBHome = (Test1SLBHome) ejbHomeObject;
            System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): test1SLBHome=" + test1SLBHome);

            test1SLB = test1SLBHome.create();
            System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): test1SLB=" + test1SLB);

            rtnValue = test1SLB.foo("pagal");
            System.out.println("P001Listener.java: contextInitialized(ServletContextEvent sce): rtnValue=" + rtnValue);

        } catch (NamingException ne) {
            ne.printStackTrace();

        } catch (ClassCastException cce) {
            cce.printStackTrace();

        } catch (RemoteException re) {
            re.printStackTrace();

        } catch (CreateException ce) {
            ce.printStackTrace();

        }
    }

    public void contextDestroyed(ServletContextEvent sce)  { 
        System.out.println("P001Listener.java: contextDestroyed(ServletContextEvent sce): inside");
    }

}

P001_EAR.EAR

在p001_ear里面。ear我有:

  • META-INF
  • p001_ejb.jar
  • P001_war.war
  • p001_ejbclient.jar

在META-INF中,我有:

  • application.xml

在p001_ejb.jar中,我有:

  • META-INF\ejb-jar.xml
  • META-INF\jboss.xml
  • META-INF\manifest.mf
  • com\p001\ejb\test1slbbean.class
  • com\p001\ejb\test1slbsession.class
    null

在p001_ejbclient.jar中,我有:

  • META-INF\manifest.mf
  • com\p001\ejb\test1slb.class
  • com\p001\ejb\test1slbhome.class
  • com\p001\ejb\test1slblocal.class
  • com\p001\ejb\test1slblocalhome.class
  • com\p001\ejb\test1slbutil.class

我跑野蝇。在server.log文件中,我看到EJB部署成功:

但是我在这一行中得到java.lang.ClassCastException:

ejbHomeObject = PortableRemoteObject.narrow(namedObject, test1SLBHomeClass);

这是server.log:

2015-12-08 11:21:59,158 INFO[stdout](MSC service thread 1-9)P001Listener.java:contextInitialized(ServletContextEvent sce):inside

2015-12-08 11:21:59,161 INFO[stdout](MSC service thread 1-9)P001Listener.java:contextInitialized(ServletContextEvent sce):test1slbHomeClass=Interface com.p001.ejb.test1slbHome

2015-12-08 11:21:59,164 INFO[stdout](MSC service thread 1-9)P001Listener.java:contextInitialized(ServletContextEvent sce):InitialContext=javax.naming.InitialContext@2db02a6a

2015-12-08 11:21:59,171信息[org.JBoss.EJB.Client](MSC服务线程1-9)JBoss EJB客户端版本2.0.1.Final 2015-12-08 11:21:59,177信息[stdout](MSC服务线程1-9)P001Listener.java:contextInitialized(ServletContextEvent sce):namedObject=Proxy for remote EJB StatelessEJBLocator{appname='P001_EAR',moduleName='P001_EJB',

2015-12-08 11:21:59,197 ERROR[stderr](MSC service thread 1-9)java.lang.ClassCastException

2015-12-08 11:21:59,198 org.jboss.com.sun.corba.se.impl.javax.rmi.portableMoteObject.narner错误[stderr](MSC服务线程1-9)(portableMoteObject.java:246)

2015-12-08 11:21:59,200 javax.rmi.portableRemoteObject.narner(portableRemoteObject.java:158)错误[stderr](MSC服务线程1-9)

2015-12-08 11:21:59,201 com.p001.listener.p001Listener.ContextInitialized(P001Listener.java:59)错误[stderr](MSC服务线程1-9)

2015-12-08 11:21:59,202 Io.undertow.servlet.core.applicationlisteners.ContextInitialized(applicationlisteners.java:173)错误[stderr](MSC服务线程1-9)

2015-12-08 11:21:59,204错误[stderr](MSC服务线程1-9)位于io.undertow.servlet.core.deploymentManagerImpl.deploymentManagerImpl.java:194)

2015-12-08 11:21:59,206 org.wildfly.extension.undertow.deployment.undertowdeploymentService.startContext(undertowdeploymentService.java:87)

2015-12-08 11:21:59,208 org.wildfly.extension.undertow.deployment.undertowdeploymentService.start(undertowdeploymentService.java:72)错误[stderr](MSC服务线程1-9)

2015-12-08 11:21:59,210 org.jboss.MSC.service.serviceControllerImpl$startTask.startService(ServiceControllerImpl.java:1948)

2015-12-08 11:21:59,211 org.jboss.MSC.service.serviceControllerImpl$startTask.run错误[stderr](MSC服务线程1-9)(ServiceControllerImpl.java:1881)

2015-12-08 11:21:59,212 java.util.concurrent.ThreadPoolExecutor.RunWorker(ThreadPoolExecutor.java:1145)错误[stderr](MSC服务线程1-9)

2015-12-08 11:21:59,214 java.util.concurrent.ThreadPoolExecutor$worker.run(ThreadPoolExecutor.java:615)错误[stderr](MSC服务线程1-9)

2015-12-08 11:21:59,215 java.lang.thread.run(thread.java:745)错误[stderr](MSC服务线程1-9)

2015-12-08 11:21:59,216由:java.lang.ClassCastException:com.sun.proxy.$Proxy21导致的错误[stderr](MSC服务线程1-9)无法强制转换为org.omg.corba.Object

2015-12-08 11:21:59,218 org.jboss.com.sun.corba.se.impl.javax.rmi.portableRemoteObject.narner错误[stderr](MSC服务线程1-9)(portableRemoteObject.java:225)

2015-12-08 11:21:59,219错误[stderr](MSC服务线程1-9)...11多

我做错了什么来得到这个错误消息?

test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB";

对此代码:

test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBHome";

然后奏效了。所以基本上,我现在查找Home的JNDI名称,然后将其强制转换为Home类。

在旧的JBoss 4.2.x中,我查找JNDI名称test1slb,然后将其强制转换为Home类,它就起作用了。那么在旧的JBoss 4.2.x中是否有一个JNDI名称test1slb同时用于远程和家庭?

共有1个答案

成浩漫
2023-03-14

我已经找到解决办法了。当我更改此代码时:

test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLB";

对此代码:

test1SLBJNDIName = "java:global/P001_EAR/P001_EJB/Test1SLB!com.p001.ejb.Test1SLBHome";

然后奏效了。所以基本上,我现在是在家里看,然后把它投到家里的类。

 类似资料:
  • 这是我的父类,有两个名为的方法。带有参数的那个在子类中使用。 这是我的子类,在子类的方法中,我使用父类的方法: 当我尝试显示子类的对象时,我得到以下错误: 线程“main”java.lang.StackOverflowError中出现异常

  • 我正在创建一个小应用程序,使用angular cli从网站url获取html内容。我已经添加并导入了所有必需的文件,但我遇到了以下错误: XMLHttpRequest无法加载https://www.test.org/publicclass/index.html.请求的资源上不存在“访问控制允许源”标头。因此不允许访问源“http://localhost:8080”。 我们如何解决这个问题。 脚本:

  • 很抱歉,我对Java知之甚少。我得到了这个代码来接管。基本上,我在 当我运行代码时。 下面是解析XML的块 这是Improts,不确定是否需要这样做 这是XML文件

  • 我还尝试了,,JMeter获得了多达8000个示例,最大时间12000ms(超时30s),并给出了错误。在拒绝之前,它至少应该排队10,000个连接。

  • 问题内容: public class Category { 在正在生成。 问题答案: 当您执行时,您称呼孩子们的。这里没有问题,只不过您在这里调用了父对象。这将称呼孩子,等等。 不错的无限循环。 摆脱它的最好方法是将您的方法更改为: 这样,您将不打印parentCategory,而仅显示其名称,不显示无限循环,不显示StackOverflowError。 编辑: 正如博洛在下面说的那样,您将需要检

  • 测试代码为: 测试代码为: 你知道怎么了吗?