【问题标题】:Using c3p0 with Tomcat 8 DataSource将 c3p0 与 Tomcat 8 数据源一起使用
【发布时间】:2016-07-14 01:06:12
【问题描述】:

我有一个加载了 DataSource 的 tomcat 8 服务器。我想知道是否可以将这个 DataSource 与 c3p0 连接池管理结合使用。到目前为止,这是我尝试过的。

上下文.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

问题是mysql在服务器启动后只显示一个进程

【问题讨论】:

    标签: hibernate c3p0


    【解决方案1】:

    我终于找到了解决方案:context.xml 资源应该是这样的

    <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 代替 url,user 代替用户名等

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-09
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      • 2010-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多