Reputation: 31
I have written a sample EJB class as shown below :
@Stateless(mappedName = "BusinessSLSB")
@Local(BusinessLocal.class)
@TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)
public class BusinessSLSB implements BusinessLocal{
//body of the class
}
I have a non-EJB class in the same project and I try to lookup the file in the following way :
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());
}
}
When I am executing the code, I am getting the following exception :
Error occurred --> Unable to resolve BusinessSLSB. Resolved '
Am I going wrong in providing the lookup name? How can I resolve this issue?
Upvotes: 0
Views: 1025
Reputation: 31
I have found the solution for such a problem. The solution is add the following lines in the web.xml file :
<ejb-local-ref>
<ejb-ref-name>ejb/BusinessLocal</ejb-ref-name>
<local>dk.tdc.soa.smo.draco.ejb.BusinessLocal</local>
</ejb-local-ref>
and the following lines in 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());
}
}
Upvotes: 0
Reputation: 3769
No usage of mappedName is ever portable. You thus can't assume that the name you assign via that attribute will always end up being a top-level JNDI name.
Which server are you using? If it supports EJB 3.1, drop mappedName and use the portable JNDI names. Otherwise drop mappedName anyway and find out what proprietary JNDI name your server assigns. Many will print this in the log when starting up.
Upvotes: 1