4 Replies Latest reply on Apr 14, 2015 2:13 AM by jharting

    using @Produces and @Inject across AS7 module dependencies

    ralf.sigmund

      Hi,

       

      is it possible to use a CDI producer method defined in module A in order to CDI inject into a bean in a second module B?

       

      Is there any description on the relation between CDI and the JBoss Modules System?

       

      In producer.jar:

       

      {code:java}

      import javax.enterprise.inject.Produces;

      import javax.enterprise.inject.spi.InjectionPoint;

      import java.util.logging.Logger;

       

      public class Producer {

       

          @Produces

          public static Logger produceLog(InjectionPoint injectionPoint) {

              return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());

          }

      }

      {code}

      In consumer.war:


      {code:java}

      import javax.inject.Inject;

      import java.util.logging.Logger;

       

       

      public class Consumer {

          @Inject

          Logger logger;

       

          public void doLog() {

              logger.info("Hello CDI with JBoss Modules");

          }

      }{code}

       

       

       

      module B has a Manifest Dependency on module A:

      {code:java}

      Manifest-Version: 1.0

      Dependencies: deployment.producer.jar

      {code}

       

      this approach leads to an weld unsatisfied dependency problem:

      {code}

      "JBAS014671: Failed services" => {"jboss.deployment.unit.\"consumer.war\".WeldService" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"consumer.war\".WeldService: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@Default] at injection point [[field] @Inject question.Consumer.logger]"

      {code}

       

       

      I posted a sample project on Github: https://github.com/sistar/jboss-cdi-demo

       

      TIA

      Ralf