1、引入的maven依赖
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
2、springboot配置c3p0数据源datasource:
@Bean(name = "root")
@Qualifier(value = "123456")
@Primary
@ConfigurationProperties(prefix = "c3p0")
public ComboPooledDataSource dataSource()
{
return DataSourceBuilder.create().type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();
}
3、application.properties中c3p0的配置信息
c3p0.jdbcUrl=jdbc:mysql:
c3p0.user=${username}
c3p0.password=${password}
c3p0.driverClass=com.mysql.jdbc.Driver
c3p0.minPoolSize=2
c3p0.maxPoolSize=10
c3p0.maxIdleTime=1800000
c3p0.acquireIncrement=3
c3p0.maxStatements=1000
c3p0.initialPoolSize=3
c3p0.idleConnectionTestPeriod=60
c3p0.acquireRetryAttempts=30
c3p0.acquireRetryDelay=1000
c3p0.breakAfterAcquireFailure=false
c3p0.testConnectionOnCheckout=false