Annotation Type Configuration


  • @Target(TYPE)
    public @interface Configuration
    Marks a class as a Configuration specification. The annotation processor adds AbstractConfiguration as superclass. Users are therefore forced to implement AbstractConfiguration.defaultValue().
    Usage example:
     @Configuration(Integer)
     class Configuration1 {
     override protected defaultValue() {
     2
     }
     }
     
     
    Leads to:
     @Component
     public class Configuration1 extends AbstractConfiguration<Integer> {@Override
     protected Integer defaultValue() {
     return Integer.valueOf(2);
     }@Autowired(required = false)
     public void setValue(@Qualifier(value = "configuration1Value") final Integer value) {
     super.setValue(value);
     }
     }
     
     

    As an alternative approach, the type of the configuration value can be specified via a field valueType. This is useful, if the type contains generics and can therefore not be specified in the value field of the annotation.
    Usage example:
     @Configuration
     class Configuration2 {
     List<Integer> valueType
     override protected defaultValue() {
     #[1]
     }
     }
     
     
    Leads to:
     @Component
     public class Configuration2 extends AbstractConfiguration<List<Integer>> {@Override
     protected List<Integer> defaultValue() {
     return Collections.<Integer>unmodifiableList(CollectionLiterals.<Integer>newArrayList(Integer.valueOf(1)));
     }@Autowired(required = false)
     public void setValue(@Qualifier(value = "configuration2Value") final List<Integer> value)
     super.setValue(value);
     }
     }
     
     
    Since:
    2.0.0
    Author:
    Oliver Libutzki <[email protected]>, Nils Christian Ehmke <[email protected]>
    See Also:
    Configuration, AbstractConfiguration
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.Class<?> value  
    • Element Detail

      • value

        java.lang.Class<?> value
        Returns:
        The type of the configuration value
        Since:
        2.0.0
        Default:
        java.lang.Void.class