将EJB 2.0的项目从JBoss 4.0迁移到TomEE时,出现错误

When moving project of EJB 2.0 from JBoss 4.0 to TomEE,It occurs errors

当我将项目从JBoss 4.0 移动到TomEE 时,出现错误! 这是我的一些 ejb-jar.xml:

<ejb-jar >

  <!-- Session Beans -->
  <session >
     <description><![CDATA[<p> RiskAssessmentRouter Manager Bean </p>]]></description>

     <ejb-name>RiskAssessmentRouterManagerBean</ejb-name>

     <home>com.spokesoft.component.riskassessmentrouter.ejb.RiskAssessmentRouterManagerHome</home>
     <remote>com.spokesoft.component.riskassessmentrouter.ejb.RiskAssessmentRouterManager</remote>
     <ejb-class>com.spokesoft.component.riskassessmentrouter.ejb.RiskAssessmentRouterManagerBean</ejb-class>
     <session-type>Stateless</session-type>
     <transaction-type>Container</transaction-type>

     <env-entry>
        <env-entry-name>daoType</env-entry-name>
        <env-entry-type>java.lang.Integer</env-entry-type>
        <env-entry-value><![CDATA[1]]></env-entry-value>
     </env-entry>
     <env-entry>
        <env-entry-name>dbNamespace</env-entry-name>
        <env-entry-type>java.lang.String</env-entry-type>
        <env-entry-value><![CDATA[null]]></env-entry-value>
     </env-entry>

     <resource-ref >
        <res-ref-name>SrsData</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
     </resource-ref>

  </session>
</enterprise-beans>

当 TomEE 启动时, 出现此错误:

com.spokesoft.component.service.ServiceException: Name [RiskAssessmentRouterManagerBean] is not bound in this Context. Unable to find [RiskAssessmentRouterManagerBean].
at com.spokesoft.component.service.RiskAssessmentRouterDelegate.handleException(RiskAssessmentRouterDelegate.java:178)
at com.spokesoft.component.service.RiskAssessmentRouterDelegate.findServices(RiskAssessmentRouterDelegate.java:78)
at com.spokesoft.http.servlet.service.RiskAssessmentRouterManager.initServices(RiskAssessmentRouterManager.java:345)
at com.spokesoft.http.servlet.service.RiskAssessmentRouter.init(RiskAssessmentRouterManager.java:138)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.tomee.catalina.TomcatWebAppBuilder.deployWar(TomcatWebAppBuilder.java:622)
at org.apache.tomee.catalina.TomcatWebAppBuilder.deployWebApps(TomcatWebAppBuilder.java:591)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:855)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:612)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:608)
at org.apache.tomee.catalina.TomcatWebAppBuilder.checkHost(TomcatWebAppBuilder.java:1973)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:133)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Thread.java:722)

代码中:

 Context ctx = new InitialContext();

Object o = ctx.lookup("RiskAssessmentRouterManagerBean");

是我的ejb-jar.xml问题还是其他一些配置问题,或者是我漏掉了一些重要的配置? 我不知道为什么,谁能帮我解决这个问题?非常感谢,

您几乎可以肯定不能在 TomEE 中使用您在 JBoss 4.0 中使用的相同 JNDI 名称。旧的 J2EE 规范没有标准化全球 JNDI 名称,因此在供应商之间迁移可能是一项艰巨的任务。 Java EE 6 和更新版本已经标准化了这些名称。

所有版本的 WildFly 都会在您的应用程序启动时记录标准化名称。也许 TomEE 做同样的事情。

如果不是,您可以通过阅读 Java EE 规范文档的第 5 节来推断它们。