【发布时间】:2014-08-25 09:42:29
【问题描述】:
我正在开发一个具有两个可能部署环境的项目,使用@Alternative(或更具体地说,@Stereotype)注释选择。我们称它们为 envDefault 和 envAlt。 我正在寻找一种方法来定义一个为 envAlt 定义了 @Alternative 但没有为 envDefault 实现 @Default 的 bean。我认为这是可行的,因为 bean 没有注入任何常见的实现,并且导致其创建的操作(它 @Observes 特定事件)不会在 envDefault 中发生。然而,由于 WeldStartService 验证时出现典型的“Unsatisfied dependencies with qualifier @Default”异常,CDI 无法启动应用程序。
有没有办法放宽对这个特定 bean 的 CDI 验证,以允许在没有 @Default 实现的情况下部署 envDefault?
编辑: 供参考,因为它已经回答:
interface AltOnlyInterface {}
@Alternative
class AltOnlyBean implements AltOnlyInterface {}
//no default implementation of AltOnlyInterface
interface OtherInterface {}
//AltOnlyInterface is not use in default environment
class RegularOtherBean implements OtherInterface {}
@Alternative
class AltOtherBean implements OtherInterface {
@Inject
AltOnlyInterface altOnlyBean;
}
【问题讨论】:
-
您能否发布一个示例,说明您如何注释这些类并禁用真正的错误消息?您是否在 beans.xml 中启用了任一替代方案?