Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading