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