3 Replies Latest reply on Mar 20, 2009 12:35 PM by vdmeerenp

    @Resource injection not working in shared library

      Hello everyone,

      I have the impression that resource injection (using @Resource annotation) is not executed when using shared library (in common/lib folder).

      I have created a HttpSessionListener , with a datasource declared like this:

      @Resource(mappedName = "java:DefaultDS")
      private DataSource ds;
      ...
      



      This listener is bundled in a jar file, which I have put under <JBOSS_HOME>/common/lib to make it available for all applications running on my Jboss application server.

      Then I have a web application which uses this HttpSessionListener by declaring it in it's web.xml.

      What I see is that when web application is deployed and listener is executed the datasource (ds) is always = null.This means the container did not execute the dependency injection of the datasource.

      Note that when I add the jar file (with listener) to WEB-INF/lib of my web application, it DOES get executed.
      So it seems that JBoss does not do dependency injection when @Resource annotations are put on classes which are in the common/lib folder.

      Could someone please help because I don't want to deploy my shared jar with each application individually.

      Many thanks in advance.

        • 1. Re: @Resource injection not working in shared library
          jaikiran

           

          This listener is bundled in a jar file, which I have put under <JBOSS_HOME>/common/lib to make it available for all applications running on my Jboss application server.

          What I see is that when web application is deployed and listener is executed the datasource (ds) is always = null.This means the container did not execute the dependency injection of the datasource.


          jars in that folder are considered just as libraries and are not scanned for deployments.

          • 2. Re: @Resource injection not working in shared library
            jaikiran

             

            Could someone please help because I don't want to deploy my shared jar with each application individually.


            Are those war applications independent of each other? If not, then you can create an EAR and package all these wars in that EAR along with that single jar containing the listener.


            • 3. Re: @Resource injection not working in shared library

               

              "jaikiran" wrote:
              Are those war applications independent of each other?


              Thanks for your quick reply, jaikiran.
              Yes the war applications are independant of each other, so I guess the only solution would be to package the jar with each war individually?

              regards,

              Pieter