在AS7模块依赖项中使用@Produces和@Inject

时间:2012-03-05 10:53:03

标签: cdi jboss7.x jboss-weld

是否可以使用模块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 拉尔夫

0 个答案:

没有答案