为什么我得到ClassCastException时访问EJB 2.1在Wildfly 8.2.1.< / h1 &



我正在使用Java 1.7, XDoclet 1.2.3, WildFly 8.2.1。最后,Eclipse Luna中的动态Web模块2.5,EJB 2.1。

  • 我有一个名为P001_EAR的企业应用程序项目。
  • 我有一个动态Web项目名为P001_WAR
  • 我有一个名为P001_EJB的EJB项目。
  • 我有一个名为P001_EJBClient的EJB客户端项目。

P001_EJB我创建了XDoclet无状态会话Bean (EJB 2.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 javax.ejb.CreateException,java.rmi.RemoteException;
}
在<<p> strong> P001_WAR 我创建了一个名为P001Listener的Listener类;在其contextInitialized方法中,我试图调用Test1SLB EJB的foo方法。这是它的代码:
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_EARWildFly。这是部署的样子:

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 于
  • meta - inf jboss.xml
  • meta - inf MANIFEST。MF
  • ejb com p001 Test1SLBBean.class
  • ejb com p001 Test1SLBSession.class

内的P001_WAR.war我有:

  • meta - inf MANIFEST。MF
  • web - inf web . xml
  • web - inf com p001 侦听器类 P001Listener.class
  • web - inf lib

内的P001_EJBClient.jar我有:

  • meta - inf MANIFEST。MF
  • ejb com p001 Test1SLB.class
  • ejb com p001 Test1SLBHome.class
  • ejb com p001 Test1SLBLocal.class
  • ejb com p001 Test1SLBLocalHome.class
  • ejb com p001 Test1SLBUtil.class

我跑了WildFly。在server.log文件中,我看到EJB已成功部署:

2015-12-08 11:21:58,671 INFO(org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor)(MSC服务线程1-3)名为Test1SLB的会话bean的JNDI绑定在部署的部署单元子部署"P001_EJB.jar"中"P001_EAR。

java:全球/P001_EAR/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBHomejava: app/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBHomejava:模块/Test1SLB ! com.p001.ejb.Test1SLBHomejava: jboss/出口/P001_EAR/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBHomejava:全球/P001_EAR/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBLocalHomejava: app/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBLocalHomejava:模块/Test1SLB ! com.p001.ejb.Test1SLBLocalHomejava:全球/P001_EAR/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBjava: app/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBjava:模块/Test1SLB ! com.p001.ejb.Test1SLBjava: jboss/出口/P001_EAR/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBjava:全球/P001_EAR/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBLocaljava: app/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLBLocaljava:模块/Test1SLB ! com.p001.ejb.Test1SLBLocal

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

ejbHomeObject = PortableRemoteObject.narrow(namedObject, test1SLBHomeClass);

server.log:

2015-12-08 11:21:59 . 158 INFO [stdout] (MSC服务线程1-9)P001Listener.java: contextInitialized(servletconttevent sce): inside

2015-12-08 11:21:59,159 INFO [stdout] (MSC服务线程1-9)P001Listener.java: contextInitialized(servletconttevent)test1SLBJNDIName = java:全球/P001_EAR/P001_EJB/Test1SLB ! com.p001.ejb.Test1SLB

2015-12-08 11:21:59 . 161 INFO [stdout] (MSC服务线程1-9)P001Listener.java: contextInitialized(servletconttevent)test1SLBHomeClass =接口com.p001.ejb.Test1SLBHome

2015-12-08 11:21:59 . 164 INFO [stdout] (MSC服务线程1-9)P001Listener.java: contextInitialized(servletconttevent)initialContext = javax.naming.InitialContext@2db02a6a

2015-12-08 11:21:59 . 171 INFO [org.jboss.ejb.](MSC服务JBoss EJB客户端版本2.0.1。最后的2015-12-0811:21:59 . 177 INFO [stdout] (MSC服务线程1-9)P001Listener.java: contextInitialized(servletconttevent)namedObject=远程EJB的代理StatelessEJBLocator{浏览器名称= ' P001_EAR ' moduleName ="P001_EJB",distinctName=', beanName='Test1SLB', view='interface .com.p001.ejb.Test1SLB’}

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

2015-12-08 11:21:59 . 198 ERROR [stderr] (MSC service thread 1-9) atorg.jboss.com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow (PortableRemoteObject.java: 246)

2015-12-08 11:21:59 . 200 ERROR [stderr] (MSC service thread 1-9) atjavax.rmi.PortableRemoteObject.narrow (PortableRemoteObject.java: 158)

2015-12-08 11:21:59 . 201 ERROR [stderr] (MSC service thread 1-9) atcom.p001.listener.P001Listener.contextInitialized (P001Listener.java: 59)

2015-12-08 11:21:59 . 202 ERROR [stderr] (MSC service thread 1-9) atio.undertow.servlet.core.ApplicationListeners.contextInitialized (ApplicationListeners.java: 173)

2015-12-08 11:21:59 . 204 ERROR [stderr] (MSC service thread 1-9) atio.undertow.servlet.core.DeploymentManagerImpl.deploy (DeploymentManagerImpl.java: 194)

2015-12-08 11:21:59 . 206 ERROR [stderr] (MSC service thread 1-9) atorg.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext (UndertowDeploymentService.java: 87)

2015-12-08 11:21:59 . 208 ERROR [stderr] (MSC service thread 1-9) atorg.wildfly.extension.undertow.deployment.UndertowDeploymentService.start (UndertowDeploymentService.java: 72)

2015-12-08 11:21:59 . 210 ERROR [stderr] (MSC service thread 1-9) atorg.jboss.msc.service.ServiceControllerImpl StartTask.startService美元(ServiceControllerImpl.java: 1948)

2015-12-08 11:21:59 . 211 ERROR [stderr] (MSC service thread 1-9) atorg.jboss.msc.service.ServiceControllerImpl StartTask.run美元(ServiceControllerImpl.java: 1881)

2015-12-08 11:21:59,212 ERROR [stderr] (MSC service thread 1-9) atjava.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java: 1145)

2015-12-08 11:21:59,214 ERROR [stderr] (MSC service thread 1-9) atjava.util.concurrent.ThreadPoolExecutor Worker.run美元(ThreadPoolExecutor.java: 615)

2015-12-08 11:21:59,215 ERROR [stderr] (MSC service thread 1-9) atjava.lang.Thread.run (Thread.java: 745)

2015-12-08 11:21:59,216 ERROR [stderr] (MSC service thread 1-9) cause .日志含义通过:java.lang.ClassCastException: com.sun.proxy。$Proxy21不能强制转换为org.omg.CORBA.Object

2015-12-08 11:21:59,218 ERROR [stderr] (MSC service thread 1-9) atorg.jboss.com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow (PortableRemoteObject.java: 225)

2015-12-08 11:21:59,219 ERROR [stderr] (MSC service thread 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用于远程和本地?

我找到了一个解决方案。当我修改这段代码时:

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然后将它投射到Home类。

在旧的JBoss 4.2。X,我查找JNDI名称Test1SLB,然后将其转换为Home类,它工作了。因此,在旧的JBoss 4.2.X中,有一个JNDI名称Test1SLB用于Remote和Home。

相关内容

  • 没有找到相关文章

最新更新