File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DI question

 
Prannav Santhosh
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 357
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prannav Santhosh
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 463
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jiafan Zhou
Ranch Hand
Posts: 193
Fedora Linux Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic