1 Reply Latest reply on Mar 2, 2009 10:50 AM by Wolfgang Knauf

    Can't inject resource when not using Servlet

    Ross Nicholson Apprentice

      I have several servlets and can inject properties easily like follows:

      @Resource(name="ConnectionFactory", mappedName="ConnectionFactory")
      private ConnectionFactory connectionFactory;

      @Resource(name="queue/out", mappedName="queue/out")
      private Destination out;

      But if I try to use a simple POJO and inject the resources it fails to work. I know the solution to this must be simple but for the life of me I can't find the answer.



        • 1. Re: Can't inject resource when not using Servlet
          Wolfgang Knauf Master

          Hi Ross,

          as far as I know, injection is only possible for certain types of resources where the server can control the usage and object creation. Those types are: SessionBeans, Servlets, JSF managed beans, ApplicationClient main classes. For everything else, JavaEE5 injection is not possible.

          The server has no chance to hook into the creation of your Pojo, so it cannot perform injection.

          Hope this helps