ame:表示你的连接池的名称也就是你要访问连接池的地址
auth:是连接池管理权属性,Container表示容器管理
type:是对象的类型
driverClassName:是数据库驱动的名称
url:是数据库的地址
username:是登陆数据库的用户名
password:是登陆数据库的密码
maxIdle:最大空闲数,数据库连接的最大空闲时间。超过空闲时间,数据库连接将被标记为不可用,然后被释放。设为0表示无限制。
MaxActive,连接池的最大数据库连接数。设为0表示无限制。
maxWait ,最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
*maxActive:最大连接数据库连接数,设 0 为没有限制
*maxIdle:最大等待连接中的数量,设 0 为没有限制
*maxWait:最大等待毫秒数, 单位为 ms, 超过时间会出错误信息
一般把maxActive设置成可能的并发量就行了
数据库连接池
c3p0是一个开源的JDBC连接池
可以在spring boot的pom文件中引用
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
重写ComboPooledDataSource类,来设置数据库连接信息
@Autowired
private Environment env;//这是个公开接口,可以使用@Autowired织入Environment来获取配置文件属性
@Bean(name="dataSource")
public ComboPooledDataSource dataSource() throws PropertyVetoException {
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setDriverClass(env.getProperty("ms.db.driverClassName"));
dataSource.setJdbcUrl(env.getProperty("ms.db.url"));
dataSource.setUser(env.getProperty("ms.db.username"));
dataSource.setPassword(env.getProperty("ms.db.password"));
dataSource.setMaxPoolSize(20);
dataSource.setMinPoolSize(5);
dataSource.setInitialPoolSize(10);
dataSource.setMaxIdleTime(300);
dataSource.setAcquireIncrement(5);
dataSource.setIdleConnectionTestPeriod(60);
return dataSource;
}