title: Need two services that share database in Tomcat 9
body: <p>I would like to run two tomcat services on two ports (8080,8181) with different codeBases, but sharing the same database resource. When I do this, I get &quot;javax.naming.NameNotFoundException: Name [comp/env/jdbc/mydb] is not bound in this Context. Unable to find [comp].&quot; when it tries to initialize the second Service.</p>
  <p>My Services look like this in the server.xml:</p>
  <pre class="lang-xml prettyprint-override"><code>  ...
    &lt;GlobalNamingResources&gt;
      &lt;Resource auth=&quot;Container&quot; name=&quot;jdbc/mydb&quot; url=&quot;jdbc:db2://myserver:50000/mydb&quot; username=&quot;xxx&quot; password=&quot;xxx&quot; .... /&gt;           
    &lt;/GlobalNamingResources&gt;
  ...
   &lt;Service name=&quot;Catalina8080&quot;&gt;
      &lt;Connector port=&quot;8080&quot; protocol=&quot;HTTP/1.1&quot; connectionTimeout=&quot;20000&quot; redirectPort=&quot;8443&quot; /&gt;
      &lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot;&gt;
  ....
        &lt;Host name=&quot;localhost&quot;  appBase=&quot;webapps8080&quot; unpackWARs=&quot;true&quot; autoDeploy=&quot;true&quot;&gt;
          &lt;Valve className=&quot;org.apache.catalina.valves.AccessLogValve&quot; directory=&quot;logs&quot; .... /&gt;
        &lt;/Host&gt;
      &lt;/Engine&gt;
    &lt;/Service&gt;
   &lt;Service name=&quot;Catalina8181&quot;&gt;
      &lt;Connector port=&quot;8181&quot; protocol=&quot;HTTP/1.1&quot; connectionTimeout=&quot;20000&quot; redirectPort=&quot;8444&quot; /&gt;
      &lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot;&gt;
  ....
        &lt;Host name=&quot;localhost&quot;  appBase=&quot;webapps8181&quot; unpackWARs=&quot;true&quot; autoDeploy=&quot;true&quot;&gt;
          &lt;Valve className=&quot;org.apache.catalina.valves.AccessLogValve&quot; directory=&quot;logs&quot; .... /&gt;
        &lt;/Host&gt;
      &lt;/Engine&gt;
    &lt;/Service&gt;
  </code></pre>
  <p>My server level context file looks like :</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;Context&gt;
  ...
  &lt;ResourceLink name=&quot;jdbc/mydb&quot; global=&quot;jdbc/mydb&quot; type=&quot;javax.sql.DataSource&quot; /&gt;
  &lt;/Context&gt;
  </code></pre>
  <p>I've tried adding and removing the Resource links at the application level context file, but nothing seems to change the outcome. Any thoughts are greatly appreciated.</p>