@Anatole: I would like to see this working even without any annotation
by matching the bean property by its name with a configuration value.
Annotations should be only needed if the default annotation free way is
not working/is not flexible enough.
WDYT?
Bye,
Oliver
Am 18.12.14 um 00:05 schrieb Anatole Tresch:
Hi all
I would like to present another use case: injection of configuration in SE
(EE should be almost similar):
Automatic Configuration (Configuration Injection)
Tamaya must provide a feature for automatic configuration, where properties
of a class or methods can be annotated:
-
Hereby the lifecycle of the instances configured should not be managed
by Tamaya.
-
String as well as other types should be supported.
-
It must be possible to define default values to be used, if no valid
value is present.
-
It must be possible to define dynamic expressions, at least for default
values.
-
The values configured can be reinjected, if the underlying configuration
changes. This should also be the case fir final classes, such as Strings.
-
Reinjection should be controllable by an loading policy.
-
It should be possible to evaluate multiple keys, e.g. current keys, and
as a backup deprecated keys from former application releases.
-
It should be possible to evaluate multiple configurations.
-
The type conversion of the properties injected should be configurable.
-
The value evaluated for a property (before type conversion) may be
adaptable as well.
-
It should be possible to observe configuration changes.
To illustrate the points above imagine the following POJO:
Configured POJO Example
*public* *class* *MyPojo* {
@ConfigProperty("myCurrency")
@DefaultValue("CHF") // use as default
@WithLoadingPolicy(LoadingPolicy.INITIAL) // load the value only
once (no reinjection)
*private* *String* currency;
@ConfigProperty("myCurrencyRate")
*private* *Long* currencyRate;
@ConfigProperty // evaluates to
key=<fieldName>="fullRate"
@ConfigProperty("fallback.property")
@WithConfig("default")
@WithConfig("moduleConfig");
*private* *BigDecimal* fullRate;
// Configuration method
*void* setStartup(@ConfigProperty *boolean* startup,
@ConfigProperty("componentName") @WithConfig("module1")
@DefaultValue("N/A") *String* compName){
...
}
// Configuration method
@ConfigProperty("componentName")
@WithConfig("module1")
@DefaultValue("N/A")
*private* *void* setComponentName(*String* compName){
...
}
// Configuration listener method, defining which properties to listen for
@ConfigChanges
@ConfigProperty("componentName")
*private* *void* setComponentName(ConfigChange change){
...
}
}
The instance then can be passed for being configured:
Configuring a POJO
MyPojo instance = *new* MyPojo();*Configuration*.configure(instance);
This will configure all values according to the load policies (by default
LoadPolicy.INITIAL). Depending on the listeners present and the properties
injected Tamaya will keep weak references to the bean and the current
environment, so it can be determined, when configuration changes must be
published into the bean.
Feel free to comment or ask questions ;)
Best,
Anatole
--
N Oliver B. Fischer
A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
P +49 30 44793251
M +49 178 7903538
E [email protected]
S oliver.b.fischer
J [email protected]
X http://xing.to/obf