一。
package com.imooc.mybatis.datasource; import com.mchange.v2.c3p0.ComboPooledDataSource; import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory; /** * mybatis和c3p0兼容 */ public class C3P0DatasourceFactory extends UnpooledDataSourceFactory { public C3P0DatasourceFactory(){ this.dataSource = new ComboPooledDataSource(); } }
二。
<environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <!-- <dataSource type="POOLED">--> <!--换c3p0的源--> <dataSource type="com.imooc.mybatis.datasource.C3P0DatasourceFactory"> <property name="driverClass" value="${driverClass}"/> <property name="jdbcUrl" value="${jdbcUrl}"/> <property name="user" value="${user}"/> <property name="password" value="${password}"/> </dataSource> </environment> </environments>