liveBook · Manning

Fallback configuration

As explained in Akka in Action, Second Edition

A fallback configuration is a lower-precedence configuration that supplies values missing from a higher-precedence configuration.

A fallback configuration supplies values that a higher-precedence configuration does not define. This avoids maintaining separate complete files for each environment: keep shared defaults in one configuration and override only deployment-specific values. section 7.1.4

Use the fallback structure to preserve predictable configuration behavior:

  • Read a property from the highest-precedence configuration first; if it is absent there, resolve it from the fallback. section 7.3.1
  • Prevent unset values from producing location-dependent behavior: requesting an unset property throws an exception rather than returning an empty value. section 7.1.4
  • Place library defaults in reference.conf files at the root of JAR files so applications can inherit required settings automatically. section 7.1.4
  • Chain configurations across Java properties, JSON, or HOCON files, and override properties with system properties when required. section 7.1.4

Override only the changed subtree

Suppose the fallback defines MyAppl.version = 10 and MyAppl.description = "My application". Lift subApplA into the higher-precedence configuration, where only description is changed to "Sub application". Then config.getString("MyAppl.description") returns "Sub application", while MyAppl.version falls through to the fallback and returns 10. Programmatically, the relationship is expressed as subApplACfg.withFallback(configuration). section 7.3.1

Figure 7.3 Priority of the configuration fallback structure. The highest priority is at the top and overrides definitions in lower files.
CH07_F03_Abraham2

Use the priority diagram to inspect how higher configuration layers override definitions in lower fallback layers. section 7.1.4

How Akka in Action, Second Edition covers it

How deep it goes
Explains precedence, missing-value behavior, library defaults, file chaining, and programmatic subtree lifting, without detailing configurator internals.
Examples
Uses shared MyAppl settings, a subApplA description override, reference.conf library defaults, and the withFallback configuration chain.
What you can do after
Operate/configure applications with layered defaults, targeted environment overrides, and predictable errors for missing properties.
How it connects
Connects configuration precedence with environment-specific configuration, configuration files, library defaults, system properties, and testing overrides.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Akka in Action, Second Edition. The section links point to the parts of the book it draws on.