Property Sources
Juneau 10.0 introduces a unified property-source model behind Settings.
When to use it
Use a property source when configuration values should come from somewhere the defaults do not cover, such as a database or a secrets service, yet still resolve through Settings, Config and the $P{...} SVL variable.
Example
import java.util.*;
import org.apache.juneau.commons.settings.*;
public class PropertySourceExample {
public static void main(String[] args) throws Exception {
// A custom source backed by a map.
Map<String,String> values = Map.of("app.greeting", "hello");
Settings.get().addSource(FunctionalPropertySource.of(values::get));
// The source is now part of the default stack.
String greeting = Settings.get().get("app.greeting").asOptional().orElse("none");
System.out.println(greeting);
}
}
Options
| Type | Role |
|---|---|
PropertySource | Read-only source of name -> Optional<String> |
PropertyStore | Read/write source (extends PropertySource) |
PropertySourceProvider | ServiceLoader SPI for auto-registering ambient sources |
Default source stack
By default, the stack resolves in this priority order (highest first):
- Thread-local overrides (
Settings.setLocal(...)) - Global overrides (
Settings.setGlobal(...)) - Sources added at runtime via
addSource(...), newest first Config(SPI priority 100)- CLI args (
ArgsPropertySource, 50) - JVM system properties (40)
- Environment variables, verbatim name (30)
.envfile (20)- Manifest entries (10)
- Relaxed environment variable names
If no registered source supplies system properties, a fallback system-property source sits just above the relaxed environment source. The environment, .env, manifest and args sources cache their lookups; system properties and runtime-added sources are read live.
Config integration
Config is explicitly wired to avoid hidden lifecycle ownership:
Config config = Config.create().build();
Settings.get().addSource(new ConfigPropertySource(config));
SVL integration
$P{key[,default]}is the unified property-stack lookup.$S,$E,$A,$MF,$Cremain source-specific lookups.