0

我编写了一个示例 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 '

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

4

2 回答 2

1

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

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

于 2012-11-20T09:55:36.140 回答
0

我已经找到了解决此类问题的方法。解决方案是在 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());
      }
}
于 2012-11-28T10:44:53.693 回答