【问题标题】:JBoss and CDI ProducerJBoss 和 CDI 制作人
【发布时间】:2015-06-05 07:23:54
【问题描述】:

我在使用适用于 WildFly 和 JEE 7 的记录器的生产者时遇到了 JBoss AS7 / JEE 6 的问题。

我创建了一个限定符:

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface BpeLogger {
}

生产者类:

public class LoggerProducer{
  @Produces
  @BpeLogger
  public Logger produceLogger(InjectionPoint injectionPoint) {
    return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
  }
}

现在我正在尝试将记录器注入另一个 CDI Bean:

  @Inject
  @BpeLogger
  private Logger logger;

部署失败,出现以下异常:

org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@BpeLogger] at injection point [[field] @Inject @BpeLogger private de.ulc.bpe.web.process.Domino.logger]

这里有什么问题?

【问题讨论】:

  • 你有 beans.xml 文件吗?它在 Java EE 6 中是强制性的,但在 Java EE 7 中是可选的。
  • 您是在 JBoss AS 7 上运行还是在 WildFly 上运行?从你的问题看不清楚。
  • 愚蠢的问题:你不是在混合 2 个不同的 Logger 类(j.u.l 与 slf4j)吗?
  • 它适用于 Wildfly,但不适用于 JBoss AS 7。
  • @XavierDury 是 slf4j...为什么你认为有混合?

标签: jakarta-ee jboss cdi


【解决方案1】:

确保 META-INF 文件夹中有 beans.xml 文件。

您也可以尝试将 LoggerProducer 类直接注释为 CDI bean。例如。添加 @Named 注释和可能的合适范围。在你的情况下,@Singleton 可能会做得很好。

@Named
public class LoggerProducer{
  @Produces
  @BpeLogger
  public Logger produceLogger(InjectionPoint injectionPoint) {
    return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
  }
}

【讨论】:

    猜你喜欢
    • 2017-01-20
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多