Skip to main content

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​

TypeRole
PropertySourceRead-only source of name -> Optional<String>
PropertyStoreRead/write source (extends PropertySource)
PropertySourceProviderServiceLoader SPI for auto-registering ambient sources

Default source stack​

By default, the stack resolves in this priority order (highest first):

  1. Thread-local overrides (Settings.setLocal(...))
  2. Global overrides (Settings.setGlobal(...))
  3. Sources added at runtime via addSource(...), newest first
  4. Config (SPI priority 100)
  5. CLI args (ArgsPropertySource, 50)
  6. JVM system properties (40)
  7. Environment variables, verbatim name (30)
  8. .env file (20)
  9. Manifest entries (10)
  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, $C remain source-specific lookups.

See also​