Search code examples
tomcatpersistencedatasourcejnditomcat8

Tomcat - Move database connection out of server.xml


I am on tomcat 8 and so far the database connection (resource) is configured in conf/server.xml

<Resource name="jdbc/onejndi"
          auth="Container"
          type="javax.sql.DataSource"
          maxTotal="8"
          maxIdle="30"
          maxWaitMillis="10000"
          username="sa"
          password=""
          driverClassName="org.hsqldb.jdbcDriver"
          url="jdbc:hsqldb:file:c:/.../>

In the applications META-INF/context.xml we have the corresponding resourcelink

<ResourceLink name="jdbc/onejndi" global="jdbc/onejndi"
              type="javax.sql.DataSource"/>

Now i am supposed to move the db connection out of the global server.xml. Putting everything in the applications META-INF/context.xml is problematic, as the application will be run in different stages with different databases and we will not be able to provide specific builds for every stage.

Do have have an idea, a hint, ... ?


Solution

  • Now i have found the solution myself.

    I place a file context.xml.default inside tomcat/conf/catalina/localhost. Structured like a standard context.xml-file and may contain resource-tags like in server.xml.

    Now i do neither need to change files of the baseline tomcat nor write database connections in the applications META-INF/context.xml.

    side note:

    • context.xml.default => is available for all applications
    • myapp.xml => is availbe only for the app with the name "myapp"