maven依赖c3p0_详解springboot使⽤c3p0数据库连接池的⽅
法
使⽤springboot开发时,默认使⽤内置的tomcat数据库连接池,经常碰到这种情况:运⾏时间⼀长,数据库连接中断了。所以使⽤c3p0连接池吧。
引⼊的maven依赖:
c3p0
c3p0
0.9.1.2
c3p0的配置信息,写到application.properties配置⽂件中,需要注意的是,c3p0的数据库⽤户名是ur不是urname:
c3p0.jdbcUrl=jdbc:mysql://ip:port/dnname?
uUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=fal
c3p0.ur=${urname}
c3p0.password=${password}
c3p0.sql.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=fal
springboot配置c3p0数据源datasource:
@Configuration
public class DatasourceConfiguration {
@Bean(name = "dataSource")
@Qualifier(value = "dataSource")
@Primary
@ConfigurationProperties(prefix = "c3p0")
public DataSource dataSource()
{
ate().hange.v2.c3p0.ComboPooledDataSource.class).build();
}
}
对于其他的⼀些数据源也可使⽤类似⽅式,当然有些数据源springboot提供了更加简洁的⽅式,需要参数官⽅⽂档。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持脚本之家。