I am using Spring Tool Suite which is Eclipse-based for my webapp along with Maven Filtering to inject the database credentials into my root context.
My pom.xml contains the following:
<profiles>
<profile>
<id>debug</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<environment.type>debug</environment.type>
<db.driver>com.mysql.jdbc.Driver</db.driver>
<db.url>jdbc:mysql://xxx:3306/xxxxx</db.url>
<db.username>xxxxxx</db.username>
<db.password>xxxxxx</db.password>
<tomcat.server>xxxxx</tomcat.server>
<tomcat.path>/xxxxx</tomcat.path>
<tomcat.url>http://xxx:8080/manager/text</tomcat.url>
<tomcat.username>xxx</tomcat.username>
<tomcat.password>xxx</tomcat.password>
</properties>
</profile>
</profiles>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<targetPath>WEB-INF</targetPath>
<includes>
<include>**/root-context.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
While my root-context.xml contains the following:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${db.driver}" />
<property name="jdbcUrl" value="${db.url}" />
<property name="user" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="maxIdleTime" value="60" />
<property name="idleConnectionTestPeriod" value="55" />
</bean>
I get no issues when I deploy to Tomcat, and similarly, when I build it with Maven my target folder contains the filtered root-context.xml.
However, when I attempt to run this webapp from Eclipse with "Run on Server..." I get the following error:
WARN : com.mchange.v2.c3p0.DriverManagerDataSource - Could not load driverClass ${db.driver}
java.lang.ClassNotFoundException: ${db.driver}
It seems the root-context.xml that gets copied over is unfiltered. Is there a way to fix this?