Define configuration file outside of the classpath

Here I describe the way I use to configure my applications. The main idea is to define a property file outside of the application, doing this, it is possible to deploy the same application in several environments (dev/test/prod) without any changes.

First of all, the property file:

The tips is to define a parameter in the Tomcat context file which points to the file location:

<Parameter name="directoryConfig" override="false" value="FILE_PATH"/>

And now, to get the value in the application, I use Spring this way:

<bean id="placeholderConfig"
	<property name="location"
		value="file:#{contextParameters.directoryConfig}/" />

This is an example of its usage to set up an Oracle datasource:

<orcl:pooling-datasource id="dataSource"
	username="${}" password="${}">

Now, we can just change the path of the configuration file, depending on each environment, to automatically have the related parameters.