Hi, I'm having a problem with JNDI lookups on the local JNDI Context (java:comp/env) in my application. Ok here is the problem A method is called in a class. I print out the java:comp/env context bindings in this method, and it shows me all the objects that I expect to be bound to java:comp/env context. Then it calls a method in another class. I again print out the java:comp/env bindings in this method. Here there are no bindings in java:comp/env. Any ideas why this might happen? Thanks
Hi Anant, I think, for example, if your SessionBean class A tries and successfully lookup a JDNI context, and then calls methods located in other classes, this lookup will NOT be carry forward to that class, you need to look it up again in that class. If you want the class notifies the JNDI context, you can pass the context to that class, and see whether it is bind. Nick.
Ok but the resources are defined in the web.xml file as <resource-ref>s so I would think that these would be available to all threads? Also how does this work with EJBs? If the resource is defined in the ejb-jar.xml file, is this resource available to the ejb's as well as the methods on other classes that the ejb invokes? For example lets take the following scenario. Res1 -> JMS Queue EJB1 -> defines Res1 in ejb-jar.xml IntClass1 -> class contained in EJB1-ejb.jar ExtLib1 -> contains ExtClass1 EJB2 -> another EJB that does not have Res1 defined EJB1 calles method on IntClass1.. is Res1 available to method? EJB1 calles method on ExtClass1.. is Res1 available to method? EJB1 looks up EJB2 and calles method on EJB2.. is Res1 available to method? Thanks, -- Anant
Please indicate how you are trying to access local reference in each method. My assumption is you are doing a lookup(java:comp/env/...) in each case. Are you "building" an Initial context in each case or are you reusing a common Context? It is the Context that either has a reference bound (at runtime) or not.
Gary Craig,<br />Author of <a href="http://www.amazon.com/exec/obidos/tg/detail/-/032118579X/qid=1060361076/sr=1-11/ref=sr_1_11/102-0063041-4226517?v=glance&s=books" target="_blank" rel="nofollow">Enterprise Java (tm) Programming with IBM Websphere, 2nd edition</a><br /><a href="http://www.amazon.com/exec/obidos/tg/detail/-/1931182116/qid=1060361262/sr=1-30/ref=sr_1_30/102-0063041-4226517?v=glance&s=books" target="_blank" rel="nofollow">Introduction to Web Application Development with IBM Websphere Studio (Certification Guide, Test 285)</a>
Joined: Dec 10, 2003
I am using java:comp/env to do the lookup Also I'm building the initial context each time. Thanks, -- Anant
It would be wise to cache the InitialContext within the Application (you could use a utility JAR service locator approach). This would allow you to use the same context for all clients and it will improve performance because you are not constantly creating the same InitialContext. Dan Co-Author of "Enterprise Java (tm) Programming with IBM Websphere, 2nd Edition".