题
我有几个组件,这些组件是范围的。根据我所处的环境,我想安装一个或另一个环境。在JBoss Seam中,我将使用@install(false),然后配置我想要的bean通过components.xml。
在CDI / Weld中是否有类似的方法?
谢谢,
沃尔特
解决方案
好吧,您始终可以使用生产者方法,并根据您的某些配置来确定要实例化的实现。请记住,在CDI中,XML的量最少。
所以,类似:
@Produces
public Component createComponent() {
if (configuration.isSomething()) {
return new ComponentImpl1();
} else {
return new ComponentImpl2();
}
}
不隶属于 StackOverflow