是否可以使用模块A中定义的CDI生成器方法,以便CDI注入第二个模块B中的bean?
是否有关于CDI和JBoss模块系统之间关系的描述?
在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());
}
}
在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");
}
}
模块B对模块A有一个Manifest Dependency:
Manifest-Version: 1.0
Dependencies: deployment.producer.jar
这种方法导致焊接不满意的依赖问题:
"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]"
我在Github上发布了一个示例项目:https://github.com/sistar/jboss-cdi-demo
TIA 拉尔夫