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"
         reloadable="true"
         
         >

  <Resource name="jdbc/phenomebank"              
            type="javax.sql.DataSource" username="" password=""
            driverClassName="org.postgresql.Driver" 
            url="jdbc:postgresql://localhost:5432/phenomebank"
            maxActive="8" maxIdle="4"
            global="jdbc/phenomebank" 
            />

               
</Context>

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:

C:\apache-tomcat-6.0.20\conf\Catalina

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

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