1、下载c3p0
2、实现 UnpooledDataSourceFactory
package com.joinhealth.esb.db; import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory; import com.mchange.v2.c3p0.ComboPooledDataSource; public class C3P0DataSourceFactory extends UnpooledDataSourceFactory { public C3P0DataSourceFactory() { this.dataSource = new ComboPooledDataSource(); } }
3、Mybatis-config.xml 配置
<dataSource type="com.joinhealth.esb.db.C3P0DataSourceFactory"> <property name="driverClass" value="com.mysql.jdbc.Driver"/> <property name="jdbcUrl" value="jdbc:mysql://192.168.10.101:3306/esb?useUnicode=true&characterEncoding=UTF-8"/> <property name="user" value="root"/> <property name="password" value=""/> <property name="idleConnectionTestPeriod" value="60" /> <property name="maxPoolSize" value="20" /> <property name="maxIdleTime" value="600" /> </dataSource>
更多 c3p0 配置参数请到 http://www.mchange.com/projects/c3p0/index.html#configuration_properties
时间: 2024-10-10 13:12:17