• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

DI question

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 463
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 193
Mac OS X Fedora Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic