4 Replies Latest reply on Aug 24, 2011 1:39 AM by ovesper

    Failure: @Resource injection into JSF-managed-bean

    ovesper

      Hi,

       

      I am trying to inject a ConnectionFactory via @Resource annotation into my JSF managed bean like the following:

       

      @ManagedBean(name="foo")

      @ViewScoped

      public class Foo implements Serializable {

        @Resource(name="java:/ConnectionFactory")

        private ConnectionFactory connectionFactory; 

      }

       

      Accessing an xhtml-page which is backed by above bean results in the following exception:

       

      Caused by: java.lang.IllegalArgumentException: No @Resource annotation found on injection point [field] @Resource private test.Foo.connectionFactory
      at org.jboss.weld.injection.spi.helpers.AbstractResourceServices.resolveResource(AbstractResourceServices.java:38)

       

      I debugged into this and actually do not understand what is going wrong as everything seems to look good (the attached screenshot from the eclipse-debugger should point out the issue). Inspecting the debug-variables I can see that my annotation is actually present BUT HashMap's getEntry-method does not find the one and only entry.

       

      Anybody got a clue what is going wrong here? The issue occurs with JBoss AS 6.0 and 6.1.

       

      One interesting point is the different "id" for the two class-objects (926 vs. 23818). Could this be the reason for the issue? Am I having a class-loading-problem or something releated?

       

      -Oliver

        • 1. Re: Failure: @Resource injection into JSF-managed-bean
          ovesper

          One interesting point is the different "id" for the two class-objects (926 vs. 23818). Could this be the reason for the issue? Am I having a class-loading-problem or something releated?

           

          There is another weird thing to mention: the annotation @Resource is located within two jars:

          1. rt.jar from the Java Runtime
          2. jboss-annotations-api_1.1_spec.jar

           

          Both classes have the same package-name (javax.annotation), but the jboss-class contains 1 more method (String lookup()). Could this cause the exceptions I'm currently facing? If yes, how am I supposed to force the usage of the correct class (whichever it may be)?

           

          Another information: in contrast to the not working @Resource-injection, the injection of EJBs using @EJB works absolutely fine.

           

          Thanks in advance.

           

          -Oliver

          • 2. Re: Failure: @Resource injection into JSF-managed-bean
            ovesper

            Is there anybody who's got my scenario (@Resource injection into a JSF managed bean) working with JBoss 6.0 or 6.1?

            • 3. Re: Failure: @Resource injection into JSF-managed-bean
              jaikiran

              Are you packaging any jar file(s) containing javax.annotation.* classes within your application? If yes, remove such jar file(s) from the application packaging.

              • 4. Re: Failure: @Resource injection into JSF-managed-bean
                ovesper

                OMG... now I feel somewhat ashamed... I actually did package common-annotation.jar with my application. I couldn't remember but always thought I was just packaging richfaces-jar files. As the jar's where NOT added to the project's buildpath I didn't locate them in eclipse when looking for jar files exposing the javax.annotation.Resource class.

                 

                Thank you very much jaikiran, I really appreciate your help!

                 

                -Oliver