Starting from the code in the official documentation, I have created the following structure:
interface Service {
String name();
}
@LookupIfProperty(name = "service.foo.enabled", stringValue = "true")
@ApplicationScoped
class ServiceFoo implements Service {
public String name() {
return "foo";
}
}
@ApplicationScoped
class ServiceBar implements Service {
@Startup
public void onStart() { // startup logic }
public String name() {
return "bar";
}
}
The code in ServiceBar.onStart() gets always executed even if the bean does not get injected. Is there a way to execute the ServiceBar startup logic only when ServiceFoo is disabled?
As already described by @ladicek,
LookupIfPropertydoes not affect enablement. As a workaround, I have changed the code in the following way:In this way, the startup logic gets executed only when ServiceFoo is not enabled. Is not super elegant, but it works.