wood burning stoves
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Dependency injection limitation in JEE ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Dependency injection limitation in JEE ?" Watch "Dependency injection limitation in JEE ?" New topic

Dependency injection limitation in JEE ?

Arpit Kumar Jain
Ranch Hand

Joined: Jun 05, 2010
Posts: 41
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.

Arpit Jain

Arpit Kumar Jain
Ranch Hand

Joined: Jun 05, 2010
Posts: 41
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.

sivan jai
Ranch Hand

Joined: Feb 24, 2010
Posts: 115
Yes you are right - DI is possible only in certain places.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33134

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Tushar Joshi Nagpur

Joined: Apr 18, 2010
Posts: 4
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 Joshi, Nagpur
I agree. Here's the link: http://aspose.com/file-tools
subject: Dependency injection limitation in JEE ?
It's not a secret anymore!