So I have a web app which I deploy / redeploy on a remote Tomcat server instance. Sometimes, the deploy and even redeploy (by redeploy I mean moving the ROOT.war through SFTP and leave Tomcat to actually redeploy it) work as expected, no issues whatsoever with the database connection. Unfortunately, other times, after redeploy, it just refuses to connect to the database, as apparently it doesn't recognize the MySQL driver anymore. The MySQL connector lib is inside Tomcat's lib folder, not package with the WAR.
pom.xml:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
<scope>provided</scope>
</dependency>
webapp/WEB-INF/web.xml:
<resource-ref>
<description>App MySQL</description>
<res-ref-name>jdbc/App_MySQL</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
webapp/META-INF/context.xml:
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink name="jdbc/App_MySQL"
global="jdbc/App_MySQL"
type="javax.sql.DataSource"/>
</Context>
var/lib/tomcat7/conf:
<GlobalNamingResources>
<Resource
name="jdbc/App_MySQL"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="root_password"
driverClassName="com.mysql.jdbc.Driver"
description="App Database"
url="jdbc:mysql://localhost:3306/"
maxActive="15"
maxIdle="3"/>
</GlobalNamingResources>
Full error below:
SEVERE: Unable to create initial connections of pool.
java.sql.SQLException
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)