Spring provides a very cool feature of passing application property values dynamically using the java -D switch.
All you need to do is define the property in the properties file and leave the value part blank.
When you run the application, say from the command line, use the -D switch to pass the
key=value for the property whose value needs to be set dynamically.
This feature is a life-saver in enterprise environments where you need to pass sensitive information to the application (like DB passwords etc.) without the knowledge of the application/developer.
During the development phase you can set the password in the properties file and test the application.
During deployment, just remove the password value from the properties file and pass the password dynamically to the application (of course, you need to have another code that reads the encrypted password from some common repository, decrypts it and then passes the value to your application).
Thus, there is no code change required to read the password dynamically.
Below screen shot provides more details:
The value for the
password property can be passed at run-time using