Springboot How to use C3P0 database connection pool __ Database

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.