When using springboot development, the built-in Tomcat database connection pool is used by default, often in this situation: a long run time, the database connection is interrupted. So use the C3P0 connection pool bar.
Introduction of MAVEN dependencies:
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
C3P0 configuration information, written to the application.properties configuration file, it should be noted that C3P0 's database username is user not username:
C3p0.jdbcurl=jdbc:mysql://ip:port/dnname?useunicode=true&characterencoding=utf8&autoreconnect=true &failoverreadonly=false
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
Springboot Configure C3P0 Data source datasource:
1 @Configuration
2 public class Datasourceconfiguration {
3
4 @Bean (name = "DataSource")
5 @ Qualifier (value = "DataSource")
6 @Primary
7 @ConfigurationProperties (prefix = "c3p0")
8 Public DataSource DataSource ()
9 {
ten return datasourcebuilder.create (). Type ( Com.mchange.v2.c3p0.ComboPooledDataSource.class). Build ();
One }
12}
Similar approaches can be used for other data sources, and of course some data sources springboot provide a more concise approach that requires the official documentation of the parameters.