5

I'm using typesafe config and I'm looking for an easy way to allow optional overrides of properties in config files that are shared between applications.

So lets say I have 2 apps, A & B. They both make use of a module Z. They both load a shared config file 'shared.conf'.

Module Z has a property defined in it's reference.conf

z.foo=bar

I'd like to be able to

#override the property for both A & B
z.foo=zap

or

#override the property for just A
a.z.foo=zip

I know I can do this for just the 'z' prefix in the application.conf of each app. e.g.

z = ${?a.z}

but I was hoping there might be a way to move all the way to the root node. e.g.

MAGICAL_ROOT = ${?a}

Is what I'm hoping for possible?

Programming Guy
  • 7,259
  • 11
  • 50
  • 59

1 Answers1

0

According to the documentation at the config github repository, the way to lift up a sub tree to the root, is not in configuration itself, but in the code.

I'll quote:

You can also use withFallback to merge in some hardcoded values, or to "lift" a subtree up to the root of the configuration; say you have something like:

foo=42
dev.foo=57
prod.foo=10

Then you could code something like:

Config devConfig = originalConfig
                    .getConfig("dev")
                    .withFallback(originalConfig)

In your case, you want something like:

Config aConfig = originalConfig
                    .getConfig("a")
                    .withFallback(originalConfig)

You can read more about Merging config trees.

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35