aspose file tools*
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
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Dependency injection limitation in JEE ?" Watch "Dependency injection limitation in JEE ?" New topic
Author

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.

Thanks
Arpit Jain


SCJP, SCWCD, SCEA
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.

Thanks
Arpit
sivan jai
Ranch Hand

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

Joined: May 26, 2003
Posts: 30537
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Tushar Joshi Nagpur
Greenhorn

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


Tushar Joshi, Nagpur
MCSD.NET, RHCE, PMP, ZCE, SCJP1.2, SCEA Part1
 
 
subject: Dependency injection limitation in JEE ?