If you found the contents in this blog useful, then please make a donation to keep this blog running. You can make donations via Skrill with email address

Sunday, September 25, 2011

Loading a Place Holder Properties file with a Environment Variable

While I was working at Virtusa, we had a requirement of externalizing the DB Configurations in a property.
The property file location was set on an Environment Variable.

We tried the conventional placeholder bean method and tried to append the properties file location with the ${ABC}/ format. But it didn't work the way we wanted it to.

Then after some reading and trial and error I was able to figure out that

<context:property-placeholder location="file:///${XYZ}/DDA/"/>

Does exactly what we require and we could use the properties in the file within the spring bean configuration using ${property name}.