Home > database >  Spring Boot Application Properties Variable Conversion/Matching when retrieved from ENV variable?
Spring Boot Application Properties Variable Conversion/Matching when retrieved from ENV variable?

Time:09-03

In my application.yaml properties file I have a variable defined as below -

service-account:
#   secret:  //commented in the yaml file, to indicate that it's used in app but read from ENV variable.

From this SOF post, I understand how . (dots) and - (dashes) are converted.
Now in the ENV variables file - I don't have anything like -

service-account.secret or service-account_secret or service_account_secret etc

instead what i have in the env (file) is - SERVICEACCOUNT_SECRET=xyz

Does spring boot match variable service-account.secret in props file with SERVICEACCOUNT_SECRET env variable.

Can someone confirm.

CodePudding user response:

Does spring boot match variable service-account.secret in props file with SERVICEACCOUNT_SECRET env variable.

Yes. The canonical form of a property is all lower-case with - and . separators. service-account.secret is in the canonical form. To convert from the canonical form to an environment variable, Spring Boot does the following:

  • Replaces dots (.) with underscores (_)
  • Removes any dashes (-)
  • Converts to uppercase

Following these steps, service-account.secret becomes SERVICEACCOUNT_SECRET so you can use the SERVICEACCOUNT_SECRET environment variable to set the service-account.secret property.

  • Related