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
localhost.datasource.properties
development.datasource.properties
production.datasource.properties
I have them conifgured like this:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/resources/properties/production.datasource.properties</value>
<value>classpath:/resources/properties/development.datasource.properties</value>
<value>classpath:/resources/properties/localhost.datasource.properties</value>
</list>
</property>
</bean>
<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}" />
</beans>
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?
Thanks