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.
SCJP, SCWCD, SCEA
Arpit Kumar Jain
posted 10 years ago
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.
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.