title: Spring datasource configuration for localhost, development, and production
body: <p>I'm trying to figure out how my Spring app can determine where it is deployed and load the appropriate datasource.  We have 3 environments...my local, the development server, and the production server.  So far I have 3 properties files called </p>
  
  <pre><code>localhost.datasource.properties
  development.datasource.properties
  production.datasource.properties
  </code></pre>
  
  <p>I have them conifgured like this:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;
  
      &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="locations"&gt;
              &lt;list&gt;
                  &lt;value&gt;classpath:/resources/properties/production.datasource.properties&lt;/value&gt;
                  &lt;value&gt;classpath:/resources/properties/development.datasource.properties&lt;/value&gt;
                  &lt;value&gt;classpath:/resources/properties/localhost.datasource.properties&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSourceMySQL" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
          p:driverClassName="${mysql.jdbc.driver.class.name}"
          p:url="${mysql.jdbc.url}"
          p:username="${mysql.jdbc.username}"
          p:password="${mysql.jdbc.password}" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>This works fine when I am on my localhost machine.  If I deploy a war file to development it is still reading the localhost properties since it is last in the list and I get an error.  What is the best way to implement this?</p>
  
  <p>Thanks</p>