我有一个在 Jboss 服务器上运行的应用程序。在 Jboss 上,它使用 JNDI 源作为数据库连接名称 cc.xml 和 iv.xml。(jboss/server/default/deploy/两个 jndi xml 都在这里)
现在我必须在 Tomcat 上部署相同的 war,并尝试从 tomcat 创建和访问 JNDI 源。我做了以下更改-
在 META-INF/Context.xml 中添加了以下代码
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/R2">
<ResourceLink name="ivrDataSource" global="ivrDataSource" type="javax.sql.DataSource" />
<Resource
name="ivrDataSource"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
password=""
maxIdle="2"
maxWait="5000"
username="user"
url="jdbc:jtds:sqlserver://abc:1433;DatabaseName=IVR_GUARDIAN;tds=8.0;lastupdatecount=false;socketKeepAlive=true;"
maxActive="4"/>
<ResourceLink name="ccDataSource" global="ccDataSource" type="javax.sql.DataSource" />
<Resource
name="ccDataSource"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
password=""
maxIdle="2"
maxWait="5000"
username="web"
url="jdbc:jtds:sqlserver://xyz:1433;DatabaseName=CC_GUARDIAN;tds=8.0;lastupdatecount=false;socketKeepAlive=true;"
maxActive="4"/>
</Context>
添加到 WEB.XML ----
<!-- FOR TOMCAT DEPLOYMRNT -TESTING -->
<resource-ref>
<description>ccDataSource</description>
<res-ref-name>ccDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>ivrDataSource</description>
<res-ref-name>ivrDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
但是我得到了错误-
javax.naming.NameNotFoundException: Name ccDataSource,ivrDataSource is not bound in this Context.
一直在 JBOSS 上工作,所以这对我来说是新的..这里遗漏了一些东西。请提出建议。
最佳答案
您不必使用 <ResourceLink>
.尝试删除 <ResourceLink>
<ResourceLink>
用于创建到全局 JNDI 资源的链接。
有关详细信息,请参阅以下链接。
http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource%20Links
希望这对您有所帮助。
关于sql-server - 尝试访问 Tomcat 服务器上的 JNDI 源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17952776/