Package io.quarkus.arc.lookup
Annotation Interface LookupUnlessProperty
@Repeatable(List.class)
@Retention(RUNTIME)
@Target({METHOD,TYPE,FIELD})
public @interface LookupUnlessProperty
Indicates that a bean should only be obtained by programmatic lookup if the property does not match the provided value.
This annotation is repeatable and may be put on a stereotype. A bean will be included if all the conditions
defined by the LookupUnlessProperty and LookupIfProperty annotations are satisfied.
interface Service {
String name();
}
@LookupUnlessProperty(name = "service.foo.disabled", stringValue = "true")
@ApplicationScoped
class ServiceFoo implements Service {
public String name() {
return "foo";
}
}
@ApplicationScoped
class ServiceBar implements Service {
public String name() {
return "bar";
}
}
@ApplicationScoped
class Client {
@Inject
Instance<Service> service;
void printServiceName() {
// This would print "bar" if the property of name "service.foo.disabled" is set to true
// Note that service.get() would normally result in AmbiguousResolutionException
System.out.println(service.get().name());
}
}
- See Also:
-
Nested Class Summary
Nested Classes -
Required Element Summary
Required ElementsModifier and TypeRequired ElementDescriptionName of the runtime property to check.ExpectedStringvalue of the runtime property (specified byname) if the bean should NOT be looked up at runtime. -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanDetermines if the bean should be looked up when the property specified bynamehas not been specified at all.Defines how thestringValueis matched against the actual property value.
-
Element Details
-
name
String nameName of the runtime property to check. -
stringValue
String stringValueExpectedStringvalue of the runtime property (specified byname) if the bean should NOT be looked up at runtime. -
lookupIfMissing
boolean lookupIfMissingDetermines if the bean should be looked up when the property specified bynamehas not been specified at all.- Default:
false
-
match
StringValueMatch matchDefines how thestringValueis matched against the actual property value.By default, exact string equality (
StringValueMatch.EQ) is used. Set toStringValueMatch.REGEXto interpretstringValueas a regular expression.- Default:
EQ
-