CDI - conditional installation
-
29-09-2019 - |
문제
I have several components which are application scoped. Depending on which environment I am in, I want to install one or the other. In JBoss Seam, I would use @Install(false), then configure the bean that I wanted through components.xml.
Is there a similar method for doing this in CDI / WELD?
Thanks,
Walter
해결책
Well, you can always use a producer method and decide which implementation to instantiate based on some configuration of yours. Remember that in CDI the amount of xml is put to minimum.
So, something like:
@Produces
public Component createComponent() {
if (configuration.isSomething()) {
return new ComponentImpl1();
} else {
return new ComponentImpl2();
}
}
제휴하지 않습니다 StackOverflow