EJB類

2012-11-19 29 views
0

我寫了一個示例EJB類,如下圖所示: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 ' 

難道我走錯了在提供查找名稱?我該如何解決這個問題?

回答

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()); 
     } 
} 
1

mappedName的使用永遠不可移植。因此,您不能認爲通過該屬性分配的名稱始終會成爲頂級JNDI名稱。

您正在使用哪臺服務器?如果它支持EJB 3.1,則刪除mappedName並使用可移植的JNDI名稱。否則,請放下mappedName並找出您的服務器分配的專有JNDI名稱。許多人會在啓動時在日誌中打印此信息。

+0

我使用WebLogic Server 10.3.3。它支持EJB 3.0。如何識別服務器分配的JNDI名稱?日誌文件不包含任何此類信息 – San