Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EJB Question

Status
Not open for further replies.

wushutwist

Programmer
Aug 3, 2000
984
US
I am trying to get a JNDI Context for a EJB from within another EJB.

We used to do it like this:
Code:
  Properties props = ctx.getEnvironment();
  try {
      Context ctx = new InitialContext(props);
      EJBHome home = (EJBHome) ctx.lookup("EJBBean");
  }
Unfortunately SessionContext.getEnvironment() is deprecated and is no longer implemented in the new version of WebLogic (which we are using). The Sun docs give this cryptic message in regards to the deprecated method:

getEnvironment()
Deprecated. Use the JNDI naming context java:comp/env to access enterprise bean's environment.

Any clues as to what this means? Any sample code? Any comments other than to pass the properties to the bean? Thanks.

Wushutwist
 
Hi.
I think you want the jndi lookup method:

As in:
Code:
// From tutorial [URL unfurl="true"]http://developer.java.sun.com/[/URL]
// developer/onlineTraining/EJBIntro
EJBHome home;
Object  ref;
Object ref  = jndiContext.lookup("DeclaredEJBName");
home = PortableRemoteObject.narrow(ref, EJBHome.class);
EJBean brown = home.create(...);
Or possibly just
Code:
home =  (EJBHome)jndiContext.lookup("DeclaredEJBName");
EJBean red = home.create(...);

Where "DeclaredEJBName" is the JDNI name you gave to the EJB application when you deployed it (on Sun's J2EE platform, that's in the deploytool)

 
Thanks,
I found the answer about an hour after I posted. In ejb 1.1 you can include other ejbs that you want to reference in your deployment descriptor and then it is very easy to do a lookup against them. This is the code to do the lookup.

Code:
InitialContext initial = new InitialContext();
objref = initial.lookup("jndi ejb home reference");
EJBHome home = (EJBHome) PortableRemoteObject.narrow(objref,EJBHome.class);

Very similar to what you posted but it will not work unless you include the deployment descriptor stuff.


Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top