Using c3p0 with Tomcat 8 DataSource

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 20:35:10

问题


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.xml

 <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-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

The problem is mysql shows only one process once the server is started


回答1:


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" />

Please note that some of the common Resource attributes are different, e.g. jdbcUrl instead of url, user instead of username, etc



来源:https://stackoverflow.com/questions/38363982/using-c3p0-with-tomcat-8-datasource

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!