File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubt with DI & JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Doubt with DI & JNDI" Watch "Doubt with DI & JNDI" New topic
Author

Doubt with DI & JNDI

Mrinal Govind
Greenhorn

Joined: Jan 18, 2005
Posts: 3
The text below is from "EJB 3 in Action" book (section 5.2.3 Looking up resources and EJBs):

"using lookups instead of DI allows you to determine which resource to use dynamically at runtime instead of being constrained to using static configuration that cannot be changed programmatically."

Can someone kindly elaborate this in layman terms?
Davide Crudo
Ranch Hand

Joined: Sep 08, 2009
Posts: 62
"using lookups instead of DI allows you to determine which resource to use dynamically at runtime instead of being constrained to using static configuration that cannot be changed programmatically."


I think that the reason is that with DI you Hardcode the resource in the bean with for instance an annotation. On Runtime, you cannot assign a variable to the annotation, so, you need to stick with it...

With Lookups, you could theorically pass the reference as a variable, so that the resource reference can be decided at runtime...

for instance:

Using DI:



Using JNDI lookup:



Dave

SCJP, SCBCD
Mrinal Govind
Greenhorn

Joined: Jan 18, 2005
Posts: 3
Dave,

Thanks a lot for the reply!
What so say does makes sense.

Regards,
Mrinal

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt with DI & JNDI