spring - 在基于 tomcat Spring 的应用程序中使用 c3p0 连接池

标签 spring tomcat6 connection-pooling c3p0

我有一个在 tomcat 6 下运行的基于 Spring 的 Web 应用程序。现在,我想使用 c3p0 连接池而不是 tomcat 的默认 DBCP。所以,来自 c3p0 help doc,我已经在 context.xml 中定义了数据源就像是:

<Resource name="jdbc/sample" auth="Container"
     driverClassName="oracle.jdbc.driver.OracleDriver"
     url="jdbc:oracle:thin:@someServer:1551:xyz"
     username="userName"
     password="pwd"
     validationQuery="SELECT 1 FROM dual"
     testOnBorrow="true"
     testWhileIdle="true"
     factory="org.apache.naming.factory.BeanFactory" 
     type="com.mchange.v2.c3p0.ComboPooledDataSource" 
     maxPoolSize="20" 
     minPoolSize="5" 
     acquireIncrement="1" 
   />

现在,文档说,我应该在 web.xml 中包含以下内容:
<resource-ref>
  <res-ref-name>jdbc/sample</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref> 

我在 applicationContext.xml 中也有以下内容:
<jee:jndi-lookup id="sampleDataSource" resource-ref="true"
    jndi-name="jdbc/sample" />

当我启动tomcat时,我得到

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context



没有 c3p0 并在 tomcat6 中使用默认连接池工作正常。

任何帮助,将不胜感激。

最佳答案

这个线程很旧,所以答案是为了将来使用-
我有同样的问题(这就是我进入这个线程的方式)。

我在进行了一次小型研究后解决了这个问题。
有一些定义,使用的数据源不支持。
当您删除这些定义并重命名其他定义时,数据源的创建没有问题
并且不需要上面提到的resourceLink。

在以下链接中,您可以找到支持的定义列表。
http://www.mchange.com/projects/c3p0/#tomcat-specific

以下链接是数据源的 java 文档。
根据那里列出的方法,您可以配置资源
context.xml 文件中的标记。
http://www.mchange.com/projects/c3p0/apidocs/com/mchange/v2/c3p0/ComboPooledDataSource.html

关于spring - 在基于 tomcat Spring 的应用程序中使用 c3p0 连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5246874/

相关文章:

java - Spring 和 Mock 框架集成

java - Sun Java System Application Server 9.1_02(内部版本 b04-fcs)上的 HTTP 状态 503

spring - 使用 spring boot 2.5.5 和 Spring Cloud 2.0.4 创建 pubsubInputChannel 时出错

java - 与tomcat上的hibernate和mysql共享c3p0连接池

java - 使用 Springs @Autowired 进行独立的 JUnit 测试

java - Tomcat 6 - 网络应用迁移

java - Commons Daemon procrun 标准输出已初始化

java - 有关事件的电子邮件通知 - Oracle Queue

java - 当连接数超过池的 maxSize 时,我的 Web 应用程序挂起

java - Apache http 客户端 -> 本地地址绑定(bind) -> 一段时间后发生 BindException