Uploaded image for project: 'CDI TCK'
  1. CDI TCK
  2. CDITCK-206

Add test to verify visibly of beans registered explicitly through an extension in non-bean archives

    XMLWordPrintable

Details

    • Feature Request
    • Resolution: Done
    • Major
    • 1.1.0.Alpha1
    • 1.0.4.Final
    • Tests
    • None
    • Compatibility/Configuration
    • 0
    • 0% 0%

    Description

      Add a test that answers this question:

      Can an extension register a bean programmatically for a class that resides in another non-bean archive?

      This question requires a short example which is available in the OpenTCK test suite and may be ported to the CDI TCK [1].

      Assume one archive, a.jar, has the following contents:

      org/opentck/javaee/cdi/spi/beforebeandiscovery/BeanClassToRegister.class

      A second archive, b.jar, has the following contents:

      org/opentck/javaee/cdi/spi/beforebeandiscovery/AnotherBeanClassToRegister.class
      org/opentck/javaee/cdi/spi/beforebeandiscovery/AnotherManualBeanRegistrationExtension.class
      org/opentck/javaee/cdi/spi/beforebeandiscovery/ManualBeanRegistrationExtension.class
      META-INF/services/javax.enterprise.inject.spi.Extension

      AnotherBeanClassToRegister has an injection point of type BeanClassToRegister:

      public class AnotherBeanClassToRegister {
      @Inject
      private BeanClassToRegister collaborator;
      }

      BeanClassToRegister and AnotherBeanClassToRegister are added as beans programmatically in respective extensions listed in the service provider descriptor:

      public class ManualBeanRegistrationExtension implements Extension {
      public void registerBeans(@Observes BeforeBeanDiscovery event, BeanManager bm)

      { event.addAnnotatedType(bm.createAnnotatedType(BeanClassToRegister.class)); }

      }

      public class AnotherManualBeanRegistrationExtension implements Extension {
      public void registerBeans(@Observes BeforeBeanDiscovery event, BeanManager bm)

      { event.addAnnotatedType(bm.createAnnotatedType(AnotherBeanClassToRegister.class)); }

      }

      The two libraries, a.jar and b.jar are bundled in a web archive, test.war

      WEB-INF/lib/a.jar
      WEB-INF/lib/b.jar
      WEB-INF/beans.xml

      Deploying this archive to the reference implementation fails with an error message that the injection point from above cannot be satisfied. There appears to be a visibility problem across bean archives in this case.

      Adding META-INF/beans.xml to a.jar and removing the ManualBeanRegistrationExtension from b.jar resolves the issue in the reference implementation.

      [1] https://github.com/opentck/javaee_cdi/tree/master/src/test/java/org/opentck/javaee/cdi/spi/beforebeandiscovery

      Attachments

        Activity

          People

            mkouba@redhat.com Martin Kouba
            dan.j.allen Dan Allen (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              PagerDuty