Sunday, February 14, 2010

Why isn't my datasource configuration being picked up in Tomcat 6?

I had an unusual problem with Tomcat 6 where changes to my database configuration stored in the /META-INF/context.xml file was not being picked up upon server restart or application reload.

Below is a sample:

<!-- antiResourceLocking="true" -->
<Context path="/phenbank"

  <Resource name="jdbc/phenomebank"              
            type="javax.sql.DataSource" username="" password=""
            maxActive="8" maxIdle="4"


When I had changed the database name from 'phenomebank' to something else like 'newdatabase', the log files continued to show that it was trying to connect to 'phenomebank' instead of 'newdatabase'

It turns out that Tomcat 6 was caching my configuration file in a separate directory, such that application reload and server restart would not automatically pick up the new configuration!!

The solution was to delete the cached files in Tomcat 6 found in this folder:


To prevent Tomcat from caching the configuration again you can edit an attribute called cachingAllowed in your context.xml as follows:

<Context path="/zebrafish"
         cachingAllowed="false"         >