Finding EJBs using InitialContext on Weblogic 10.xx

Could you tell me how to search for EJB on Weblogic?
I have the following bean:

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

I need this bean in another class that is not part of the managed content (just a simple class), so I think it should be done as follows:

 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.xx AS?
Any help would be appreciated.

+4
source share
1 answer

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 { ... } 

Search for EJBs from a class deployed in a single 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 like this:

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

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

 DataAccessBean#<package>.DataAccessRemote 
+7
source

All Articles