Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clarifiaction needed on DI and JNDI

 
Suresh Magi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

1. What is the difference between DI and JNDI ??

2. Why does DI not compatible outside the container ??

3. What is the use of @Resource annotation at the class level and how is it different from the field level ??

Thanks,
Suresh
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suresh,

It isn't really practical to answer these questions in a forum post, they are simply too extensive. I would suggest picking up a good reference on EJB 3/Java EE 5.

In short, JNDI is used as the central registry for all container managed objects such as data sources and EJBs. Java EE 5 DI will allow you to declaratively inject objects managed by the container into other managed objects, typically from JNDI.

DI cannot be processed when a container is not present simply because there is nothing to process the container annotations. That being said, you can use either application client containers or embedded containers, both of which are designed to be used outside the application servers, inside Java SE environments.

@Resource on the class is used to declare dependencies so that look-ups can be used more easily via the EJBContext. @Resouce annotations on fields/methods result in resources actually being injected, although it still has the side-effect of declaring a dependency in the EJB context.

Hope this helps,
Reza
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic