user3139545
user3139545

Reputation: 7374

Building dynamic configuration paths in spring boot

I have an external configuration with keys that changes depending on what environment im in. I need to be able to do something like this:

application.yml

external_val: ${${LOCAL_ENV_VAR}-external-path}

That is first I need to use the environment variables to substitute a path for the external source, then I need this path the be resolved in the external configuration source.

The only thing I can get working is hard coding the values as such:

application.yml

external_val: ${preprod-external-path}

What is the appropriate way of doing nested properties lookup in Spring Boot?

Upvotes: 0

Views: 339

Answers (1)

Abdelghani Roussi
Abdelghani Roussi

Reputation: 2817

Instead of doing it like this :

external_val: ${${LOCAL_ENV_VAR}-external-path}

you can split it into 2 properties, like :

local_env_var_external_path: ${LOCAL_ENV_VAR}-external-path
external_val: ${local_env_var}

Upvotes: 1

Related Questions