3 Replies Latest reply on Mar 27, 2015 4:30 AM by Martin Kouba

    InjectionTarget.getInjectionPoints() ignores static field injection points

    Emily Jiang Newbie

      While trying to use cdi in the application client container, I found out the InjectionTarget.getInjectionPoints() does not include the injection points declaring on static fields. However, in the EE7 spec, it states:

       

      The component classes listed with support level “Limited” only support Java EE field injection and the PostConstruct callback. Note that these are application client main classes, where field injection is into static fields.

       

      In order to support the field injection on the static field of the main classes, InjectionTarget.getInjectionPoints() should lists all injection pointes including static fields. Any thoughts or I missed something?

        • 1. Re: InjectionTarget.getInjectionPoints() ignores static field injection points
          Martin Kouba Master

          Well, I think a CDI container is not required to support application client jar bean archives (see also 12.1. Bean archives). And to my knowledge, the proposal to support injection of static fields/methods was rejected during the work on CDI 1.1.

          • 2. Re: InjectionTarget.getInjectionPoints() ignores static field injection points
            Emily Jiang Newbie

            Thanks Martin for your quick response! In the CDI 1.2 spec, it states:

             

            When determining which archives are bean archives, the container must consider:

            • Library jars, EJB jars or application client jars

            • The WEB-INF/classes directory of a war

            • Directories in the JVM classpath

            The container is not required to support application client jar bean archives.


            It suggests the container must consider application client jars as bean archives but it is not required to support it. If it is not required to support, what is the point to consider the application client jars? I feel it contradicts itself.

             

            In EE7 spec, under the section Application Client EE.10.4, it says

             

            The component classes listed with support level “Limited” only support Java EE field injection and the PostConstruct callback. Note that these are application client main classes, where field injection is into static fields.

            It suggests application clients should support CDI.

             

            However, in EE7 spec EE.5.24, it says:

            In Java EE, support for dependency injection annotations as specified in the Dependency Injection for Java specification is mediated by CDI. Containers must support injection points annotated with the javax.inject.Inject annotation only to the extent dictated by CDI.

             

            It seems CDI spec has more authority than ee7 spec. Am I right to say that even if an application server doesn't support cdi for client application jars, it can still pass EE7 spec compliance tests?

            • 3. Re: InjectionTarget.getInjectionPoints() ignores static field injection points
              Martin Kouba Master
              It suggests the container must consider application client jars as bean archives but it is not required to support it. If it is not required to support, what is the point to consider the application client jars? I feel it contradicts itself.

              Yes, it sounds a bit odd. I believe that the intent was to list all the archives which could become bean archives.

              It seems CDI spec has more authority than ee7 spec. Am I right to say that even if an application server doesn't support cdi for client application jars, it can still pass EE7 spec compliance tests?

              The CDI TCK does not test application client jars. I'm not sure about EE 7 TCK as a whole.