如何在Tomcat 6中配置全局JNDI数据源? [英] How to configure a global JNDI datasource in Tomcat 6?

查看:180
本文介绍了如何在Tomcat 6中配置全局JNDI数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力在Tomcat 6.0.32中配置一个简单的JNDI池数据源。

I'm struggling to configure a simple JNDI pooled datasource in Tomcat 6.0.32.

我想在Web应用程序工件之外创建数据源定义。基本上,我不希望我的应用程序知道访问数据库服务器的凭据。
我当时的假设是,像在Weblogic中一样,应该可以在Tomcat中创建全局 JNDI数据源,但是到目前为止,我一直没有成功。

I want to create the datasource definition outside my web application artifact. Basically I don't want my application to know the credentials to access the database server. I was under the assumption that, like in Weblogic, it should be possible to create a "global" JNDI datasource in Tomcat, but so far I have been unsuccessful.

我试图在CATALINA_HOME / conf / context中添加数据源定义:

I have tried to add the datasource definition in CATALINA_HOME/conf/context:

<Resource name="jdbc/mydb"
 auth="Container"
 type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
 factory="oracle.jdbc.pool.OracleDataSourceFactory"
 url="jdbc:oracle:thin:@1.1.1.1.:xxx"
 user="xxxx"
 password="yyyy"/>

结果是服务器在引导时输出以下行:

The result is that the server outputs the following line, when booting:

SEVERE: Null component Catalina:type=DataSource,path=/,host=localhost,class=javax.sql.DataSource,name="jdbc/mydb"

任何指针都会受到赞赏。

Any pointer would be appreciated.

推荐答案

将数据源配置移动到server.xml < GlobalNamingResources> 。 (并且不要忘记将驱动程序jar文件添加到tomcat lib中)。
配置您的context.xml,以便所有应用程序都知道全局资源。

Move your data source configuration to server.xml <GlobalNamingResources>. (And don't forget to add the driver jar file to tomcat lib). Configure your context.xml so that all Application are aware of the global resource.

<Context>
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <ResourceLink global="jdbc/mydb" name="jdbc/mydb" type="javax.sql.DataSource"/>
</Context>

这篇关于如何在Tomcat 6中配置全局JNDI数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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