在Tomcat 8 DataSource中使用c3p0 [英] Using c3p0 with Tomcat 8 DataSource
本文介绍了在Tomcat 8 DataSource中使用c3p0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个加载了DataSource的tomcat 8服务器。我想知道是否可以将此DataSource与c3p0连接池管理结合使用。到目前为止,这是我试过的。
Context.xml
I have a tomcat 8 server with a DataSource loaded. I want to know if it is possible to use this DataSource combined with c3p0 connection pool management. So far this is what I've tried.
<Context>
...
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxIdle="30" maxTotal="100" maxWaitMillis="10000"
name="jdbc/store" password="text" type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/db" username="user"/>
</Context>
hibernate.cfg.xml
hibernate.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.datasource">
java:comp/env/jdbc/store
</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
...more stuff
问题是mysql只显示一个进程一旦服务器启动了
The problem is mysql shows only one process once the server is started
推荐答案
我终于找到了解决方案:context.xml资源应该像这样
I have finally found the solution: the context.xml Resource should go like this
<Resource auth="Container"
name="jdbc/store"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
driverClass="com.mysql.jdbc.Driver"
minPoolSize="5" maxPoolSize="10"
factory="org.apache.naming.factory.BeanFactory"
jdbcUrl="jdbc:mysql://localhost:3306/database"
user="user" password="text" />
请注意,一些常见的资源属性是不同的,例如jdbcUrl代替网址,用户代替用户名等。
Please note that some of the common Resource attributes are different, e.g. jdbcUrl instead of url, user instead of username, etc
这篇关于在Tomcat 8 DataSource中使用c3p0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文