Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2143

Same CDI extension in multiple wars in ear only loaded once

XMLWordPrintable

      When multiple wars, in the same ear, share a library with a CDI extension, the CDI extension is only loaded for 1 of the wars. If, for example, this CDI extension registers a bean, this bean is only available in one of the wars, resulting in an unsatisfied dependency.

      I've attached a demo-project, with 4 modules:

      • a shared lib with a CDI extension
      • 2 (almost) identical wars
      • an ear, containing both wars

      The wars, when deployed directly, function fine. However, when deployed together in the ear, you get the following exception:

      Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type TestBean with qualifiers @Default
        at injection point [BackedAnnotatedField] @Inject private nl.topicus.TestServlet2.testBean
        at nl.topicus.TestServlet2.testBean(TestServlet2.java:0)
      

      The exception is triggered in TestServlet1 or TestServlet2, depending on the order of initialization.

      As war1 and war2 use different classloaders for loading TestExtension, I expect the extension to load for both wars, with a different instance of 'TestBean'. Stepping through the code, I noticed that the extension is instantiated and registered twice, however AfterBeanDiscovery only fires on one of the two. This seems to be caused by org.jboss.weld.resolution.TypeSafeResolver.findMatching overwriting the first extension by the second in 'result'. ExtensionObserverMethodImpl implements equals and hashCode via its id, which contain no information about the BeanManager.

              mkouba@redhat.com Martin Kouba
              papegaaij Emond Papegaaij (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: