Adam Hughes

For some reason, this super handy trick has eluded me for years. Note I’m summarizing this from a guide: Figured it was worth repeating.

Imagine you have a spring app with the following properties


And you’d like to override these parameters at run time via env variables. Instead of defining special variable placeholders as is commonly suggested eg:


just set env. variables using the following convention

prop           env_var
foo -> FOO -> FOO_BAR
foo.barBaz -> FOO_BAR_BAZ -> FOO_BAR-BAZ

In other words, spring knows implicitly to look for env_variables of the same name as property with the . and camelcase replaced by _

Hope this helps!