• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dependency injection limitation in JEE ?

 
Arpit Kumar Jain
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Is it a limitation of JEE 5.0, that resources can be injected in any of the container managed class only like Servlet, Web Services end points,Bean, interceptors,listener classes, JAX-RPC handlers?

I feel, there is no such restriction using jndi look up in J2EE 1.4.

I have kept this post in this forum, because i need to evaluate whether i should use jndi look ups or dependency injections.

Thanks
Arpit Jain
 
Arpit Kumar Jain
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My requirement is, I should be able to inject one resource in any of the POJO. I feel "Bean" can be used for that purpose. Which can have getter/setter for injected property.

Please validate my understanding.

I am sorry, if it has caused any confusion.

Thanks
Arpit
 
sivan jai
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right - DI is possible only in certain places.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34965
377
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arpit,
That is correct. You can still use the old JNDI approach if you need a lookup elsewhere. Or inject the dependency in a session bean/servlet and pass it to the class that needs it.
 
Tushar Joshi Nagpur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dependency Injection is a newer concept and got invented to de-couple the creation of the objects and the usage of the objects. DI also makes your classes testable independently.

If you need some objects dependency injected into any of your classes, you can choose other DI solutions like Spring, Guice, Picocontainer even in Java EE scenerio.

If you used a JNDI lookup directly in one of your class then that class does not remain testable without the JNDI mechanism. This can be solved by making a Factory class which will create the object with the same JNDI mechanism and dependency Injection to use that factory class as the object creation method.

with regards
Tushar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic