• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dependency injection limitation in JEE ?

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right - DI is possible only in certain places.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic