SPRING Quick Tip: Setting application property values dynamically!

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:

Spring - Setting property values dynamically
The value for the password property can be passed at run-time using -Dpassword=bingo

This entry was posted in Java, Quick Tips, Spring and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s