1 Reply Latest reply on Oct 21, 2013 3:02 PM by texanhogman

    CDI bean discovery across Modules on 7.2

    texanhogman

      Using jboss-as-7.2.0.Final, I am having an issue with CDI visibility of a transitive bean dependencies when my beans are deployed as JBoss modules.

       

      Component defintions

      web application name: module-test

      bean 1 name: foo

      bean 2 name: bar

       

      The goal here is to utilize CDI across these components e.g. module-test will @Inject foo and foo will @Inject bar

       

      The challenge comes in when I suggest that module-test should not know about bar and therefore should not have to define a dependency on bar for CDI scanning to work.

       

      I have created sample project to demonstrate what I am trying to do.

       

      First this GITHub project/tag shows things working correctly but the application is explicitly calling out the dependency on bar as shown in the jboss-deployment-structure.xml.

       

      This tag shows what I expect to be able to do but CDI is not registering the bar bean.  The changes are to jboss-deployment-structure.xml to remove the dependency on bar and playing with the foohttps://github.com/TexanHogman/jboss-validation/blob/no-bar-4-cdi/foo/src/main/resources/module.xmlmodule.xml to export bar to allow visibility to the CDI bean discovery.  I went through the jboss-module source and since the meta-inf attribute is not supported as with jboss-deployment-structure and I found that META-INF is not exported, even with export="true" I tried different exports as shown.

       

       

      Hopefully I have explained my issue but if not let me restart -- "Transitive CDI bean dependencies should not require application knowledge".

       

      I hope I am just missing a simple configuration setting in my module.xml

       

      Thanks for the help

      Rick

        • 1. Re: CDI bean discovery across Modules on 7.2
          texanhogman

          After debugging through the JBoss modules source, I have identified the solution.  By default, a module dependency does not import or export the META-INF directory; this is true with or without the export="true" attribute.  Without META-INF, of course CDI scanning will not occur.  After a debug session, I realized I could explicitly export the META-INF; it take did me a while to also realize I need to import it as well.

           

          The updated module.xml for my Foo module now looks like this

           

          <module xmlns="urn:jboss:module:1.1" name="org.hogdev.play.foo" slot="1.1.0">

            <resources>

            <resource-root path="foo-1.1.0.jar" />

            </resources>

            <dependencies>

            <module name="org.hogdev.play.bar" slot="1.1.0" export="true">

            <imports>

                  <include-set>

                      <path name="META-INF"/>

                  </include-set>

                  </imports>

            <exports>

                  <include-set>

                     <path name="META-INF"/>

                  </include-set>

                  </exports>

            </module>

            <module name="javax.annotation.api" />

            <module name="javax.inject.api" />

            </dependencies>

          </module>