Annotation Interface LookupIfProperty


@Repeatable(List.class) @Retention(RUNTIME) @Target({METHOD,TYPE,FIELD}) public @interface LookupIfProperty
Indicates that a bean should only be obtained by programmatic lookup if the property matches the provided value.

This annotation is repeatable. A bean will be included if all the conditions defined by the LookupIfProperty and LookupUnlessProperty annotations are satisfied.

 
  interface Service {
     String name();
  }

  @LookupIfProperty(name = "service.foo.enabled", stringValue = "true")
  @ApplicationScoped
  class ServiceFoo implements Service {

     public String name() {
        return "foo";
     }
  }

  @ApplicationScoped
  class ServiceBar {

     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.enabled" was set to false
        // Note that service.get() would normally result in AmbiguousResolutionException
        System.out.println(service.get().name());
     }
  }
  
 
See Also:
  • Instance
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static @interface 
     
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Name of the runtime property to check
    Expected String value of the runtime property (specified by name) if the bean should be looked up at runtime.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Determines if the bean is to be looked up when the property name specified by name has not been specified at all
  • Element Details

    • name

      String name
      Name of the runtime property to check
    • stringValue

      String stringValue
      Expected String value of the runtime property (specified by name) if the bean should be looked up at runtime.
    • lookupIfMissing

      boolean lookupIfMissing
      Determines if the bean is to be looked up when the property name specified by name has not been specified at all
      Default:
      false