Spring boot integrated MyBatis deep pit c3p0 detailed configuration

Source: Internet
Author: User

Project Address: Https://gitee.com/zhangjunqing/spring-boot/tree/master/springboot-mybatis-notice

I in the C3P0 data source integration process, the need to configure a variety of parameters, but according to the network of various data configuration found to test the wrong

1 Scene reproduction The configuration of many data sources on the Web is configured in a similar manner as follows:

2 Trace Debug View the value of the data source Acquireincrement in spring is still the default value of 3

3 data sources can only be configured manually

Idea: Add a data source configuration class, inject spring boot data source information into the configuration class, generate DataSource, and configure the following classes:

 PackageCom.springboot.config;ImportJavax.annotation.Resource;ImportJavax.sql.DataSource;ImportOrg.springframework.beans.factory.annotation.Qualifier;ImportOrg.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;Importorg.springframework.boot.context.properties.ConfigurationProperties;ImportOrg.springframework.context.annotation.Bean;Importorg.springframework.context.annotation.Primary; Public classdatasourceconfiguration {@Bean (name= "DataSource") @Qualifier (value= "DataSource") @Primary @ConfigurationProperties (prefix= "Spring.datasource")      PublicDataSource DataSource () {returnDatasourcebuilder.create (). Type (Com.mchange.v2.c3p0.ComboPooledDataSource.class). build (); }}

4 The startup parameters are as follows:

Spring:  DataSource:    jdbcurl:jdbc:mysql://localhost:3306/test    user:root    Password:     DriverClass:com.mysql.jdbc.Driver    Type:com.mchange.v2.c3p0.ComboPooledDataSource    acquireincrement:11    acquireretryattempts:7

Special Note: The configuration here is not the same as the above url,username, the configuration details should refer to the C3P0 combopooleddatasource parameters, similar to the following:

5 testing, data injection is correct, and tested things are normal

6 view class Datasourcebuilder, find that it seems like spring's connection pool is the default integration configuration of these several, if you use other data sources such as the above method of Ali should also apply

Spring boot integrated MyBatis deep pit c3p0 detailed configuration

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.