美文网首页
springboot使用c3p0连接池

springboot使用c3p0连接池

作者: Mrmcling | 来源:发表于2019-11-17 09:58 被阅读0次

使用springboot开发时,使用c3p0连接池。

引入的maven依赖:

<dependency>

  <groupId>c3p0</groupId>

  <artifactId>c3p0</artifactId>

  <version>0.9.1.2</version>

</dependency>

c3p0的配置信息,写到application.properties配置文件中,需要注意的是,c3p0的数据库用户名是user不是username:

c3p0.jdbcUrl=jdbc:mysql://ip:port/dnname?useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false

c3p0.user=root

c3p0.password=123456

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

springboot配置c3p0数据源datasource:

@Configuration

publicclassDatasourceConfiguration {

 @Bean(name = "dataSource")

 @Qualifier(value = "dataSource")

 @Primary

 @ConfigurationProperties(prefix = "c3p0")

 publicDataSource dataSource()

 {

  returnDataSourceBuilder.create().type(com.mchange.v2.c3p0.ComboPooledDataSource.class).build();

 }

}

相关文章

网友评论

      本文标题:springboot使用c3p0连接池

      本文链接:https://www.haomeiwen.com/subject/nxqpictx.html