VarResolver.DEFAULT
VarResolver.DEFAULT is a reusable, thread-safe VarResolver instance pre-configured with the most commonly-needed source variables. Because it is immutable and shared, you can reference it directly from anywhere without constructing your own resolver.
Built-in variables
| Variable | Class | Resolves against |
|---|---|---|
$S{key[,default]} | SystemPropertiesVar | Java system properties (System.getProperty) |
$E{key[,default]} | EnvVariablesVar | OS environment variables (System.getenv) |
$EF{key[,default]} | EnvFileVar | A .env-style env file on the filesystem |
$DE{key[,default]} | DotenvVar | A .env dotenv file |
$A{key[,default]} | ArgsVar | JVM command-line arguments |
$MF{key[,default]} | ManifestFileVar | Classpath META-INF/MANIFEST.MF entries |
Each variable accepts an optional comma-separated default that is returned when the key cannot be resolved.
Usage
// Resolve a single system-property variable.
String s = VarResolver.DEFAULT.resolve("The Java home directory is $S{java.home}");
Variables can be arbitrarily nested — the resolved value of one variable can itself contain variables, and a variable's default can be another variable:
// Look up a value in priority order:
// 1) the MYPROPERTY environment variable,
// 2) the 'my.property' system property if the env var is not set,
// 3) the literal 'not found' if neither is set.
String s = VarResolver.DEFAULT.resolve("$E{MYPROPERTY,$S{my.property,not found}}");
Resolving a string that contains no variables is a no-op that returns the input unchanged, so it is safe (and cheap) to run arbitrary text through the resolver.
Extending the default resolver
VarResolver.DEFAULT is a starting point, not a dead end. Use copy() to derive a new resolver that
inherits its variables and adds your own:
// Derive a resolver that also supports a custom $MY{...} variable.
VarResolver vr = VarResolver.DEFAULT.copy()
.vars(MyCustomVar.class)
.build();
See also
- Simple Variable Language — the full SVL reference, including the
#{...}function-call syntax. - VarResolvers — creating and configuring your own resolvers.
- SVL Other Notes — escaping and recursion caveats.
- Microservice VarResolver — how the microservice adds variables to the default resolver.