0

I am working with an ancient legacy web app which I need to prepare for continuous integration by separating resource configuration from the app itself (so that we can make a single WAR file that works on every environment assuming config file presence in some predetermined filesystem locations outside the app server).

Unlike our other, more modern web apps that use a Spring context, this one gets its database configuration via app server context and it is located in META-INF/context.xml, which looks something like

<?xml version='1.0' encoding='utf-8'?>
<!--
    Context configuration file for the Tomcat Administration Web App
-->

<Context docBase="axis2" reloadable="true" crossContext="true">
    <Resource 
        name="jdbc/GWSDEV" 
        auth="Container"
        type="javax.sql.DataSource"
        factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
        username="myuser" 
        password="mypasswd"
        driverClassName="org.postgresql.Driver"
        url="jdbc:postgresql://my.server.com/mydb" 
        maxActive="100"
        maxIdle="30" 
        maxWait="10000" />
</Context>

I would like to move this config somewhere outside the Tomcat app and reconfigure the app to load a properties file from something like /etc/myancientapp/datasource.props so that I can build a single WAR file without embedded config in Jenkins and deploy the same war in every environment and not have to build a separate one for each environment differing only in that one file. Then the config would be different in every environment but I can live with a fixed path (/etc/myancientapp/datasource.props).

How can I separate this configuration out of my app and replace it with a pointer to a config file that is to be loaded from outside the app?

amphibient
  • 29,770
  • 54
  • 146
  • 240
  • Copy Resource definition to tomcat/conf/server.xml file, add resource-ref to mywebapp/WEB-INF/web.xml file. See https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JDBC_Data_Sources and https://tomcat.apache.org/tomcat-7.0-doc/config/globalresources.html – Whome May 04 '17 at 21:09
  • that was the config remains within the server. I would like it to actually reside outside (see the file path i provided) with a pointer ref to that file. under your proposal, i would still have to edit server.xml in all of my environments and I am trying to minimize config-ing... – amphibient May 04 '17 at 21:13
  • meant to say "that WAY the config remains within the server" – amphibient May 04 '17 at 21:18
  • Subclass this factory and override createDataSource method could work I guess. http://grepcode.com/file/repo1.maven.org/maven2/org.apache.tomcat/tomcat-dbcp/7.0.0/org/apache/tomcat/dbcp/dbcp/BasicDataSourceFactory.java?av=f – Whome May 04 '17 at 21:20

0 Answers0