mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Add initialSize configuration property to datasource auto configuration
fixes #206
This commit is contained in:
parent
edaaac8993
commit
62e02d3d81
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -47,6 +47,8 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
|
||||
|
||||
private int minIdle = 8;
|
||||
|
||||
private int initialSize = 10;
|
||||
|
||||
private String validationQuery;
|
||||
|
||||
private boolean testOnBorrow = false;
|
||||
@ -122,6 +124,10 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
|
||||
this.driverClassName = driverClassName;
|
||||
}
|
||||
|
||||
public void setInitialSize(int initialSize) {
|
||||
this.initialSize = initialSize;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
@ -158,6 +164,10 @@ public abstract class AbstractDataSourceConfiguration implements BeanClassLoader
|
||||
this.testOnReturn = testOnReturn;
|
||||
}
|
||||
|
||||
public int getInitialSize() {
|
||||
return this.initialSize;
|
||||
}
|
||||
|
||||
protected int getMaxActive() {
|
||||
return this.maxActive;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -42,6 +42,11 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat
|
||||
|
||||
private BasicDataSource pool;
|
||||
|
||||
public CommonsDataSourceConfiguration() {
|
||||
// Ensure to set the correct default value for Commons DBCP
|
||||
setInitialSize(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
logger.info("Hint: using Commons DBCP BasicDataSource. It's going to work, "
|
||||
@ -55,6 +60,7 @@ public class CommonsDataSourceConfiguration extends AbstractDataSourceConfigurat
|
||||
if (getPassword() != null) {
|
||||
this.pool.setPassword(getPassword());
|
||||
}
|
||||
this.pool.setInitialSize(getInitialSize());
|
||||
this.pool.setMaxActive(getMaxActive());
|
||||
this.pool.setMaxIdle(getMaxIdle());
|
||||
this.pool.setMinIdle(getMinIdle());
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -45,6 +45,7 @@ public class TomcatDataSourceConfiguration extends AbstractDataSourceConfigurati
|
||||
if (getPassword() != null) {
|
||||
this.pool.setPassword(getPassword());
|
||||
}
|
||||
this.pool.setInitialSize(getInitialSize());
|
||||
this.pool.setMaxActive(getMaxActive());
|
||||
this.pool.setMaxIdle(getMaxIdle());
|
||||
this.pool.setMinIdle(getMinIdle());
|
||||
|
Loading…
Reference in New Issue
Block a user