Variables
Config files can contain variables that get resolved dynamically using the previously-described {@link oaj.svl.VarResolver} API.
#--------------------------
# My section
#--------------------------
[MySection]
# A system property
locale = $S{java.locale, en_US}
# An environment variable
path = $E{PATH, unknown}
# Another value in this config file
anotherLocale = $C{MySection/locale}
# Look for system property, or env var if that doesn't exist, or a default value if that doesn't exist.
nested = $S{mySystemProperty,$E{MY_ENV_VAR,$C{MySection/anotherLocale}}}
# A POJO with embedded variables
aBean = {foo:'$S{foo}',baz:$C{MySection/anInt}}
Config c = Config.create().build();
Locale locale = cf.getObject("MySection/locale", Locale.class);
String path = cf.getString("MySection/path");
int sameAsAnInt = cf.getInt("MySection/sameAsAnInt");
ABean bean = cf.getObject("MySection/aBean", ABean.class);
By default, Configs use the {@link oaj.svl.VarResolver#DEFAULT} variable resolver
which provides support for the following variables and constructs:
- {@link oaj.svl.vars.SystemPropertiesVar} - $S{key[,default]}
- {@link oaj.svl.vars.EnvVariablesVar} - $E{key[,default]}
- {@link oaj.config.vars.ConfigVar} - $C{key[,default]}
The variable resolver is controlled via the following setting:
- {@link oaj.config.Config#CONFIG_varResolver}
Additionally, the following method can be used to retrieve a Config with a different variable resolver:
- {@link oaj.config.Config#resolving(VarResolverSession)}