Managing database connection strings securely for any microservice is critical; often, we secure the username and password using the environment variables and never factor in masking or hiding the database hostname. In reader and writer database instances, there would be a mandate in some organizations not to disclose the hostname and pass that through an environment variable at runtime during the application start. This article discusses configuring the hostname through environment variables in the properties file.
Database Configurations Through Environment Variables
We would typically configure the default connection string for Spring microservices in the below manner, with the database username and password getting passed as the environment variables.