{title:'Variables', updated:'9.0.0'}

Config files can contain variables that get resolved dynamically using the previously-described {@link oaj.svl.VarResolver} API.

##### Example:

| #-------------------------- | # 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 config = Config. create().build(); | | Locale locale = config.get("MySection/locale").as(Locale. class).orElse(null); | String path = config.get("MySection/path").asString().orElse(null); | int sameAsAnInt = config.get("MySection/sameAsAnInt").asInteger().orElse(null); | ABean bean = config.get("MySection/aBean").as(ABean. class).orElse(null);

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.Builder}
  - {@link oaj.config.Config.Builder#varResolver(VarResolver) varResolver(VarResolver)}

Additionally, the following method can be used to retrieve a Config with a different variable resolver:

- {@link oaj.config.Config}
  - {@link oaj.config.Config#resolving(VarResolverSession) resolving(VarResolverSession)}