Chris Fowler
Chris Fowler

Reputation: 13

Need two services that share database in Tomcat 9

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 "javax.naming.NameNotFoundException: Name [comp/env/jdbc/mydb] is not bound in this Context. Unable to find [comp]." when it tries to initialize the second Service.

My Services look like this in the server.xml:

  ...
  <GlobalNamingResources>
    <Resource auth="Container" name="jdbc/mydb" url="jdbc:db2://myserver:50000/mydb" username="xxx" password="xxx" .... />           
  </GlobalNamingResources>
...
 <Service name="Catalina8080">
    <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
    <Engine name="Catalina" defaultHost="localhost">
....
      <Host name="localhost"  appBase="webapps8080" unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" .... />
      </Host>
    </Engine>
  </Service>
 <Service name="Catalina8181">
    <Connector port="8181" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8444" />
    <Engine name="Catalina" defaultHost="localhost">
....
      <Host name="localhost"  appBase="webapps8181" unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" .... />
      </Host>
    </Engine>
  </Service>

My server level context file looks like :

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

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.

Upvotes: 1

Views: 196

Answers (1)

Piotr P. Karwasz
Piotr P. Karwasz

Reputation: 16045

You should change the name of your <Engine> in the second service: there can be only one naming context for each combination of engine name, host name and context name.

In your case the combination (Catalina, localhost, your application name) probably appears twice, hence you should be able to find an entry like this:

SEVERE [main] naming.namingContextCreationFailed

in the logs and JNDI doesn't work in the second context.

Upvotes: 1

Related Questions