This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes DI question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "DI question" Watch "DI question" New topic
Author

DI question

Prannav Santhosh
Greenhorn

Joined: May 09, 2009
Posts: 29
In distributed environment , assume that an EJB is deployed in Machine A and if a client which is on Machine B wants to access the EJB , can i still use the Dependency Injection concept for getting access to the EJB from the client which is running on a Machine B ?
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
I think this is the point of having a Remote and Local interface, you use a Local interface if the EJB is in the same machine, and the Remote interface if the EJB is on another machine, in the end DI is translated to a JNDI operation by the EJB3 container, so I would say yes its possible.


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Prannav Santhosh
Greenhorn

Joined: May 09, 2009
Posts: 29
Hi thanks for the reply, when we do the a remote lookup ,we get the reference of the JNDI context of the server in which the EJB is deployed and we initialize a hashtable with the url ,.and other information and then we do a lookup using the JNDI name.
But my quesiton here is that if we use @EJB how does the above steps happen ? hope i am clear with my question.
Sai Surya
Ranch Hand

Joined: Feb 08, 2006
Posts: 457

Prannav Santhosh wrote:Hi thanks for the reply, when we do the a remote lookup ,we get the reference of the JNDI context of the server in which the EJB is deployed and we initialize a hashtable with the url ,.and other information and then we do a lookup using the JNDI name.
But my quesiton here is that if we use @EJB how does the above steps happen ? hope i am clear with my question.


That is the beauty of EJB3 which gives developer flexibility by hiding complex JNDI lookups. The container takes care of JNDI lookup
once it sees @EJB annotation. DI is opposite to JNDI. In the traditional JNDI look up, develoepr has to write code to look for the conainer managed resources. However, in DI the container injects the necessary resources. With this, developer can focus more on implementing business logic rather than writing infrastructure code. You can think DI as a higher level abstraction of JNDI.

Hope this helps.


Sai Surya, SCJP 5.0, SCWCD 5.0, IBM 833 834
http://sai-surya-talk.blogspot.com, I believe in Murphy's law.
Jiafan Zhou
Ranch Hand

Joined: Sep 28, 2005
Posts: 192

Prannav Santhosh wrote:In distributed environment , assume that an EJB is deployed in Machine A and if a client which is on Machine B wants to access the EJB , can i still use the Dependency Injection concept for getting access to the EJB from the client which is running on a Machine B ?

I don't believe DI works in this context here and I think it is one of the biggest disadvantage of EJB3.

I am a beginner of EJB3 as well, but the first thing has already bothered me when trying to write a Hello World EJB example code was to use Dependency Injection (like @EJB) for a client outside a J2EE container (or namely a EJB container). And it simply does not work. Because DI makes sure it is the container's responsibility to inject an object based on the dependency declaration. In such a case, JNDI is the only way to look up the Enterprise Bean's Business interface. In other words, DI works only inside the EJB container.


SCJP, SCJD, SCWCD, SCBCD, SCEA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DI question