一,pom文件
<dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.4</version> </dependency>
二,配置文件
c3p0.jdbcUrl=jdbc:mysql://x.x.x.x:xx/xxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&&serverTimezone=Asia/Shanghai c3p0.user=root c3p0.password=123456 c3p0.driverClass=com.mysql.cj.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
配置类
@Configuration public class DataSourceConfig { @Bean(name = "dataSource") @Qualifier(value = "dataSource") @Primary @ConfigurationProperties(prefix = "c3p0") public DataSource dataSource() { return DataSourceBuilder.create().type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build(); } }