I am working with Wildfly atm and I am trying to get into @Annotations. Having several implementations for some interfaces I want my application to pick a certain implementation depending on some condition (depending on a system-property, specified in my standalone.xml).
Can you point me to some hints to read up how to achieve such behaviour.
I don't want to directly specify the implementation as an @Alternative, since i want to bundle various injections with some system-property settings.
<system-properties>
<property name="env" value="stage"/>
</system-properties>
public interface LoginServerDao {
public String test();
}
@MyCustomConditionalAnnotation(env = "live")
public class LoginServerDaoImpl implements LoginServerDao {
@Override
public String test() {
return "live";
}
}
@MyCustomConditionalAnnotation(env = "stage")
public class DummyLoginServerDaoImpl implements LoginServerDao {
@Override
public String test() {
return "dummy";
}
}
@???
public @interface MyCustomConditionalAnnotation {
String env() default "test";
???
}
I really appreciate any help with this (or refering to some completely different solution/pattern I might not even have thought about).
Thanks in advance!
I finally found the solution to my problem!
Stereotypes
Found the answer on stackoverflow here: Disable @Alternative classes
@Cassio Mazzochi Molin explained under Writing your own alternative stereotype