7

Could you please tell me how to lookup EJB on Weblogic?
I have following bean:

@Stateless
@EJB(name = "DataAccess", beanInterface = DataAccessLocal.class)
public class DataAccess implements DataAccessLocal {
    ...
}

I need this bean in other class which is not part of managed content (just simple class), so I guess it should be done like this:

DataAccessLocal dataAccess = DataAccessLocal.class.cast((new InitialContext()).lookup("%SOME_JNDI_NAME%"));

The question is what should be used as %SOME_JNDI_NAME% in case of Weblogic 10.x.x AS?
Any help will be appreciated.

kardanov
  • 575
  • 3
  • 13
  • 25

1 Answers1

9

I would update your EJB class to look like this:

@Stateless(name="DataAccessBean", mappedName="ejb/DataAccessBean")
@Remote(DataAccessRemote.class)
@Local(DataAccessLocal.class)
public class DataAccess implements DataAccessLocal, DataAccessRemote {
    ...
}

Looking up the EJB from a class deployed in the same EAR (using the local interface):

InitialContext ctx = new InitialContext(); //if not in WebLogic container then you need to add URL and credentials.
// use <MAPPED_NAME>
Objet obj = ctx.lookup("java:comp/env/ejb/DataAccessBean");

EJB injection is usually preferred, and you can do it as follows:

@EJB(name="DataAccessBean")
DataAccessLocal myDataAccessBean;

If you are trying to use the EJB remotely then you will need to use the remote interface and the following JNDI name:

DataAccessBean#<package>.DataAccessRemote
Jeff West
  • 1,563
  • 9
  • 11
  • Thank you @Jeff, I've just tried it out (with local interface) and got following exception: (I don't have full stacktrace but the main part is) "remaining name: env/ejb/DataAccessBean". Do you have any ideas? – kardanov Aug 17 '11 at 14:44
  • happy to help via email - jeffrey.west@oracle.com. We can post the solution here when we are done... – Jeff West Aug 17 '11 at 15:38
  • Also, if you are trying to access the EJB from outside the EAR where the EJB is deployed, or if the EJB is deployed in its own ejb-jar you will need to sue the remote method. – Jeff West Aug 17 '11 at 17:32
  • thank you. So far usage of remote interface is enought for me,but that's strange cause I make a call from the same EAR. If you will have any ideas about the problem, it could be nice if you let me know. – kardanov Aug 18 '11 at 07:31
  • The generated JNDI name only works with the remote interface class. The local interface is not added to JNDI in WebLogic 10.3.x. I describe this at more length [here](http://stackoverflow.com/questions/3094427/publishing-ejbs-local-interface-in-weblogic/16031914#16031914) – pharsicle Apr 16 '13 at 22:09