4

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:

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());
    }
}

In consumer.war:

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");
    }
}

module B has a Manifest Dependency on module A:

Manifest-Version: 1.0
Dependencies: deployment.producer.jar

this approach leads to an weld unsatisfied dependency problem:

"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]"

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

TIA Ralf

Ralf Sigmund
  • 517
  • 1
  • 4
  • 13
  • Not an answer but just a pointer to a similar unanswered question on the JBoss community boards: https://community.jboss.org/thread/196129 – stefanglase Mar 06 '12 at 08:04
  • Another pointer to the JBoss community boards where a solution is explained that has to be implemented in the consumer: https://community.jboss.org/thread/194955 – stefanglase Mar 06 '12 at 11:34

0 Answers0