aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Using JNDI lookup to get access to the EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Using JNDI lookup to get access to the EJB" Watch "Using JNDI lookup to get access to the EJB" New topic
Author

Using JNDI lookup to get access to the EJB

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi , i am new to EJB , using @EJB works fine , but when i tried with JNDI lookup, its not working . The deployment is successful in weblogic10.




Do we need to use @EJB in the servlet when we are not doing Injection ?? Please reply .


Save India From Corruption - Anna Hazare.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


Anybody on this please.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

I am sorry my question is wrong , we should use SessionContext for lookup operations.
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Ravi,

You have three options:

1. Declare the dependency using @EJB at the class level (most EJB 3 references should cover this).
2. Use XML DD (web.xml) to declare the dependency (WebLogic 10 references should cover this).
3. Use global JNDI names (WebLogic 10 references should cover this).

Why are you using look-ups in this case in the first place?

Regards,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

1. Declare the dependency using @EJB at the class level (most EJB 3 references should cover this).

For stateless session beans , i would do as above .

Use XML DD (web.xml) to declare the dependency



This is where i am getting confused , cant i use sessioncontext.lookup (passing EJB mappedname inside it) without mentioning anything in web.xml ejb-reference ??

Can you please clarify this please

Thanks in advance
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Not sure what you mean. The EJB session context is not accessible in the web layer. You cannot use global JNDI names in the EJB context look-up method.

Also, what is it that you are trying to accomplish? Is this an "exam" question? I think the SCBD forum is more appropriate for that sort of thing.

Hope it helps,
Reza
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Reza tthanks one more clarification , You mean to say this is not possible??




// Assuming there is a Bean implementation statefull session bean.
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
An EJB session context cannot be injected into a Servlet.

Hope it helps,
Reza
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Ya , Reza , that was nice . Becuase i was getting confused with this :





[url]http://72.14.235.132/search?q=cache:_yNZH_DO8xoJ:www.javapassion.com/j2ee/JavaEE5.pdf+%40resource+sessioncontext+ctx&cd=40&hl=en&ct=clnk&gl=in
[/url]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using JNDI lookup to get access to the EJB