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);
}
}