在基于 Spring 的 Tomcat 应用程序中使用 c3p0 连接池
我有一个基于 Spring 的 Web 应用程序在 tomcat 6 下运行。现在,我想使用 c3p0 连接池而不是 tomcat 的默认 DBCP。因此,从 c3p0 帮助 文档中,我定义了数据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:名称 jdbc 未在此上下文中绑定
如果没有 c3p0 并且在 tomcat6 中使用默认连接池工作正常。
任何帮助将不胜感激。
I have a Spring Based Web App running under tomcat 6. Now, I want to use c3p0 connection pooling instead of tomcat's default DBCP. So, from the c3p0 help doc, I have defined the data source in context.xml
something like:
<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"
/>
Now, the documentation says, I should Include the following in 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>
I also have the following in applicationContext.xml
:
<jee:jndi-lookup id="sampleDataSource" resource-ref="true"
jndi-name="jdbc/sample" />
When I start the tomcat, I get
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
Without c3p0 and using default connection pooling in tomcat6 works fine.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还需要 context.xml 中的一个条目,例如:
我同意 J2EE 有太多的间接级别。请注意,context.xml 可以驻留在 Tomcat 的“conf”目录中,也可以驻留在 Web 应用程序的 META-INF 目录中(具体取决于您希望数据源适用于所有 Web 应用程序还是仅适用于特定的 Web 应用程序)。使用 context.xml 条目,您不需要 web.xml 中的资源引用。
You need an entry in context.xml as well, e.g.:
I'd agree that J2EE has far too many levels of indirection. Note that context.xml can reside either in the "conf" directory of Tomcat or the META-INF directory of the webapp (depending if you want the data source to be for all web apps or only a specific one). With the context.xml entries, you don't need the resource-ref in web.xml.
该线程已旧,因此答案供将来使用 -
我有同样的问题(这就是我到达这个线程的方式)。
我进行了一些小研究后解决了这个问题。
有一些定义,所使用的数据源不支持。
当您删除这些定义并重命名其他定义时,创建数据源没有问题
并且不需要上面提到的资源链接。
在以下链接中,您可以找到支持的定义列表。
http://www.mchange.com/projects/c3p0/#tomcat-specific
以下链接是数据源的 java 文档。
根据那里列出的方法,您可以配置资源
context.xml 文件中的标记。
http://www.mchange.com/projects /c3p0/apidocs/com/mchange/v2/c3p0/ComboPooledDataSource.html
this thread is old, so the answer is for future use -
i had the same issue (this is how i got to this thread).
i solved the problem after performing a small research.
there are some definitions, that the used data source doesn't support.
when you remove those definitions and rename others, the data source is created with no problem
and without a need to the resourceLink mentioned above.
in the following link you can find the list of supported definitions.
http://www.mchange.com/projects/c3p0/#tomcat-specific
the following link is to the data source's java doc.
according to the methods that are listed there, you can configure the resource
tag in the context.xml file.
http://www.mchange.com/projects/c3p0/apidocs/com/mchange/v2/c3p0/ComboPooledDataSource.html