【问题标题】:EJB class not identified in context lookup在上下文查找中未识别 EJB 类
【发布时间】:2012-11-19 12:55:07
【问题描述】:

我已经编写了一个示例 EJB 类,如下所示:

@Stateless(mappedName = "BusinessSLSB")
@Local(BusinessLocal.class)
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public  class BusinessSLSB implements BusinessLocal{

            //body of the class

}

我在同一个项目中有一个非 EJB 类,我尝试通过以下方式查找文件:

public class GetTransactionData {
private BusinessLocal business;
public GetTransactionDataForMercury(){
    notifier.info("Creating an object of GetTransactionData");
    try{
        InitialContext ctx = new InitialContext();
        business = (BusinessLocal) ctx.lookup("BusinessSLSB");
    }catch(Exception ne){
        notifier.error("Error occurred --> " + ne.getMessage());
    }
}

当我执行代码时,出现以下异常:

Error occurred --> Unable to resolve BusinessSLSB. Resolved '

我在提供查找名称时出错了吗?我该如何解决这个问题?

【问题讨论】:

    标签: ejb-3.0


    【解决方案1】:

    mappedName 的使用永远不会是可移植的。因此,您不能假设您通过该属性分配的名称将始终是顶级 JNDI 名称。

    您使用的是哪个服务器?如果它支持 EJB 3.1,则删除 mappedName 并使用可移植的 JNDI 名称。否则无论如何都要删除 mappedName 并找出您的服务器分配的专有 JNDI 名称。许多人会在启动时将其打印在日志中。

    【讨论】:

    • 我正在使用 weblogic server 10.3.3。它支持 EJB 3.0。如何识别服务器分配的 JNDI 名称?日志文件不包含任何此类信息
    【解决方案2】:

    我已经找到了解决此类问题的方法。解决方案是在 web.xml 文件中添加以下行:

    <ejb-local-ref> 
        <ejb-ref-name>ejb/BusinessLocal</ejb-ref-name> 
        <local>dk.tdc.soa.smo.draco.ejb.BusinessLocal</local> 
     </ejb-local-ref>
    

    以及 GetTransactionData 中的以下几行:

    public class GetTransactionData {
          private BusinessLocal business;
          public GetTransactionDataForMercury(){
          notifier.info("Creating an object of GetTransactionData");
          try{
             InitialContext ctx = new InitialContext();
             business = (BusinessLocal) ctx.lookup("java:comp/env/ejb/BusinessLocal");
             }catch(Exception ne){
          notifier.error("Error occurred --> " + ne.getMessage());
          }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多