需要两个在 Tomcat 9 中共享数据库的服务 [英] Need two services that share database in Tomcat 9

查看:43
本文介绍了需要两个在 Tomcat 9 中共享数据库的服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个端口(8080,8181)上使用不同的代码库运行两个 tomcat 服务,但共享相同的数据库资源.当我这样做时,我得到javax.naming.NameNotFoundException: Name [comp/env/jdbc/mydb] is not bound in this Context.无法找到 [comp]."当它尝试初始化第二个服务时.

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.

我的服务在 server.xml 中如下所示:

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.

推荐答案

你应该在第二个服务中更改你的的名称:可以有引擎名称主机名上下文名称的每种组合只有一个命名上下文.

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.

在您的情况下,组合(Catalinalocalhost、您的应用程序名称)可能出现两次,因此您应该能够找到这样的条目:

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

在日志中,而 JNDI 在第二个上下文中不起作用.

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

这篇关于需要两个在 Tomcat 9 中共享数据库的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆