Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt with DI & JNDI

 
Mrinal Govind
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
 
Mrinal Govind
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave,

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

Regards,
Mrinal

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic