Variables
Config files can contain variables that get resolved dynamically using the previously-described VarResolver API.
See the guide: Externalize config with INI/YAML and variables
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);
String anotherLocale = config.get("MySection/anotherLocale").asString().orElse(null);
ABean bean = config.get("MySection/aBean").as(ABean.class).orElse(null);
By default, Configs use the VarResolver.DEFAULT
variable resolver which provides support for the following variables and constructs:
$S{key[,default]}$E{key[,default]}$C{key[,default]}The variable resolver is controlled via the following setting:
Additionally, the following method can be used to retrieve a Config with a different variable resolver:
See also
- Externalize config with INI/YAML and variables: a guided walkthrough.
${xxx}shortcut — Spring-style placeholder syntax that lowers to$P{...}(unified property lookup) and supports${key:default}defaulting.- @Value Annotation Basics — declarative configuration injection
using
@Value("${...}")on beans, including the Spring Bootapplication.yamlbridge.
In This Section
📄️ 2.5.3.1. Logic Variables
The dedicated $IF{}/$SW{}/$CO{}/$PM{}/$NE{}/$UC{}/$LC{} variable classes described in earlier
📄️ 2.5.3.2. Property Sources
Juneau 10.0 introduces a unified property-source model behind