Annotation Type 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. A bean will be included if all of the conditions defined by the LookupUnlessProperty and LookupIfProperty annotations are satisifed.

     
      interface Service {
         String name();
      }
    
      @LookupUnlessProperty(name = "service.foo.disabled", 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.disabled" is set to true
            // Note that service.get() would normally result in AmbiguousResolutionException
            System.out.println(service.get().name());
         }
      }
      
     
    See Also:
    Instance
    • Required Element Summary

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

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean lookupIfMissing
      Determines if the bean should be suppressed when the property name specified by name has not been specified at all
    • Element Detail

      • name

        String name
        Name of the runtime time property to check
      • stringValue

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

        boolean lookupIfMissing
        Determines if the bean should be suppressed when the property name specified by name has not been specified at all
        Default:
        false