spring-configuration-metadata.json

spring-boot-autoconfigure-2.0.0.M7.jar!/META-INF/spring-configuration-metadata.json

 {
"sourceType": "org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari",
"name": "spring.datasource.hikari",
"sourceMethod": "dataSource(org.springframework.boot.autoconfigure.jdbc.DataSourceProperties)",
"type": "com.zaxxer.hikari.HikariDataSource"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.allow-pool-suspension",
"type": "java.lang.Boolean"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.auto-commit",
"type": "java.lang.Boolean"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.catalog",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.connection-init-sql",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.connection-test-query",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.connection-timeout",
"type": "java.lang.Long"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.data-source-class-name",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.data-source-j-n-d-i",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.data-source-properties",
"type": "java.util.Properties"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.driver-class-name",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.health-check-properties",
"type": "java.util.Properties"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.health-check-registry",
"type": "java.lang.Object"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.idle-timeout",
"type": "java.lang.Long"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"deprecated": true,
"name": "spring.datasource.hikari.initialization-fail-fast", //initializationFailTimeout > 0
"type": "java.lang.Boolean",
"deprecation": {}
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.initialization-fail-timeout",
"type": "java.lang.Long"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.isolate-internal-queries",
"type": "java.lang.Boolean"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.jdbc-url",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"deprecated": true,
"name": "spring.datasource.hikari.jdbc4-connection-test", //废弃
"type": "java.lang.Boolean",
"deprecation": {}
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.leak-detection-threshold",
"type": "java.lang.Long"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.login-timeout", //在HikariDataSource及PoolBase中
"type": "java.lang.Integer"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.max-lifetime",
"type": "java.lang.Long"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.maximum-pool-size",
"type": "java.lang.Integer"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.metric-registry",
"type": "java.lang.Object"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.metrics-tracker-factory",
"type": "com.zaxxer.hikari.metrics.MetricsTrackerFactory"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.minimum-idle",
"type": "java.lang.Integer"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.password",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.pool-name",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.read-only",
"type": "java.lang.Boolean"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.register-mbeans",
"type": "java.lang.Boolean"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.scheduled-executor",
"type": "java.util.concurrent.ScheduledExecutorService"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"deprecated": true,
"name": "spring.datasource.hikari.scheduled-executor-service",
"type": "java.util.concurrent.ScheduledThreadPoolExecutor",
"deprecation": {}
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.schema",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.transaction-isolation", //transactionIsolationName
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.username",
"type": "java.lang.String"
},
{
"sourceType": "com.zaxxer.hikari.HikariDataSource",
"name": "spring.datasource.hikari.validation-timeout",
"type": "java.lang.Long"
},

HikariConfig

HikariCP-2.7.6-sources.jar!/com/zaxxer/hikari/HikariConfig.java

@SuppressWarnings({"SameParameterValue", "unused"})
public class HikariConfig implements HikariConfigMXBean
{
private static final Logger LOGGER = LoggerFactory.getLogger(HikariConfig.class); private static final char[] ID_CHARACTERS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
private static final long CONNECTION_TIMEOUT = SECONDS.toMillis(30);
private static final long VALIDATION_TIMEOUT = SECONDS.toMillis(5);
private static final long IDLE_TIMEOUT = MINUTES.toMillis(10);
private static final long MAX_LIFETIME = MINUTES.toMillis(30);
private static final int DEFAULT_POOL_SIZE = 10;
//...... /**
* Default constructor
*/
public HikariConfig()
{
dataSourceProperties = new Properties();
healthCheckProperties = new Properties(); minIdle = -1;
maxPoolSize = -1;
maxLifetime = MAX_LIFETIME;
connectionTimeout = CONNECTION_TIMEOUT;
validationTimeout = VALIDATION_TIMEOUT;
idleTimeout = IDLE_TIMEOUT;
initializationFailTimeout = 1;
isAutoCommit = true; String systemProp = System.getProperty("hikaricp.configurationFile");
if (systemProp != null) {
loadProperties(systemProp);
}
} @Override
public void setConnectionTimeout(long connectionTimeoutMs)
{
if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes."); if (connectionTimeoutMs == 0) {
this.connectionTimeout = Integer.MAX_VALUE;
}
else if (connectionTimeoutMs < 250) {
throw new IllegalArgumentException("connectionTimeout cannot be less than 250ms");
}
else {
this.connectionTimeout = connectionTimeoutMs;
}
} @Override
public void setIdleTimeout(long idleTimeoutMs)
{
if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes."); if (idleTimeoutMs < 0) {
throw new IllegalArgumentException("idleTimeout cannot be negative");
}
this.idleTimeout = idleTimeoutMs;
} @Override
public void setMaximumPoolSize(int maxPoolSize)
{
if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes."); if (maxPoolSize < 1) {
throw new IllegalArgumentException("maxPoolSize cannot be less than 1");
}
this.maxPoolSize = maxPoolSize;
} @Override
public void setMinimumIdle(int minIdle)
{
if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes."); if (minIdle < 0) {
throw new IllegalArgumentException("minimumIdle cannot be negative");
}
this.minIdle = minIdle;
} @Override
public void setValidationTimeout(long validationTimeoutMs)
{
if (sealed) throw new IllegalStateException("The configuration of the pool is sealed once started. Use HikariConfigMXBean for runtime changes."); if (validationTimeoutMs < 250) {
throw new IllegalArgumentException("validationTimeout cannot be less than 250ms");
} this.validationTimeout = validationTimeoutMs;
} public void validate()
{
if (poolName == null) {
poolName = generatePoolName();
}
else if (isRegisterMbeans && poolName.contains(":")) {
throw new IllegalArgumentException("poolName cannot contain ':' when used with JMX");
} // treat empty property as null
catalog = getNullIfEmpty(catalog);
connectionInitSql = getNullIfEmpty(connectionInitSql);
connectionTestQuery = getNullIfEmpty(connectionTestQuery);
transactionIsolationName = getNullIfEmpty(transactionIsolationName);
dataSourceClassName = getNullIfEmpty(dataSourceClassName);
dataSourceJndiName = getNullIfEmpty(dataSourceJndiName);
driverClassName = getNullIfEmpty(driverClassName);
jdbcUrl = getNullIfEmpty(jdbcUrl); // Check Data Source Options
if (dataSource != null) {
if (dataSourceClassName != null) {
LOGGER.warn("{} - using dataSource and ignoring dataSourceClassName.", poolName);
}
}
else if (dataSourceClassName != null) {
if (driverClassName != null) {
LOGGER.error("{} - cannot use driverClassName and dataSourceClassName together.", poolName);
// NOTE: This exception text is referenced by a Spring Boot FailureAnalyzer, it should not be
// changed without first notifying the Spring Boot developers.
throw new IllegalStateException("cannot use driverClassName and dataSourceClassName together.");
}
else if (jdbcUrl != null) {
LOGGER.warn("{} - using dataSourceClassName and ignoring jdbcUrl.", poolName);
}
}
else if (jdbcUrl != null || dataSourceJndiName != null) {
// ok
}
else if (driverClassName != null) {
LOGGER.error("{} - jdbcUrl is required with driverClassName.", poolName);
throw new IllegalArgumentException("jdbcUrl is required with driverClassName.");
}
else {
LOGGER.error("{} - dataSource or dataSourceClassName or jdbcUrl is required.", poolName);
throw new IllegalArgumentException("dataSource or dataSourceClassName or jdbcUrl is required.");
} validateNumerics(); if (LOGGER.isDebugEnabled() || unitTest) {
logConfiguration();
}
} private void validateNumerics()
{
if (maxLifetime != 0 && maxLifetime < SECONDS.toMillis(30)) {
LOGGER.warn("{} - maxLifetime is less than 30000ms, setting to default {}ms.", poolName, MAX_LIFETIME);
maxLifetime = MAX_LIFETIME;
} if (idleTimeout + SECONDS.toMillis(1) > maxLifetime && maxLifetime > 0) {
LOGGER.warn("{} - idleTimeout is close to or more than maxLifetime, disabling it.", poolName);
idleTimeout = 0;
} if (idleTimeout != 0 && idleTimeout < SECONDS.toMillis(10)) {
LOGGER.warn("{} - idleTimeout is less than 10000ms, setting to default {}ms.", poolName, IDLE_TIMEOUT);
idleTimeout = IDLE_TIMEOUT;
} if (leakDetectionThreshold > 0 && !unitTest) {
if (leakDetectionThreshold < SECONDS.toMillis(2) || (leakDetectionThreshold > maxLifetime && maxLifetime > 0)) {
LOGGER.warn("{} - leakDetectionThreshold is less than 2000ms or more than maxLifetime, disabling it.", poolName);
leakDetectionThreshold = 0;
}
} if (connectionTimeout < 250) {
LOGGER.warn("{} - connectionTimeout is less than 250ms, setting to {}ms.", poolName, CONNECTION_TIMEOUT);
connectionTimeout = CONNECTION_TIMEOUT;
} if (validationTimeout < 250) {
LOGGER.warn("{} - validationTimeout is less than 250ms, setting to {}ms.", poolName, VALIDATION_TIMEOUT);
validationTimeout = VALIDATION_TIMEOUT;
} if (maxPoolSize < 1) {
maxPoolSize = (minIdle <= 0) ? DEFAULT_POOL_SIZE : minIdle;
} if (minIdle < 0 || minIdle > maxPoolSize) {
minIdle = maxPoolSize;
}
}
}

可以看到在set方法添加了参数校验,同时在configuration的构造器以及getConnection方法中也调用了validate方法

  public HikariDataSource(HikariConfig configuration)
{
configuration.validate();
configuration.copyStateTo(this);
this.seal(); LOGGER.info("{} - Starting...", configuration.getPoolName());
pool = fastPathPool = new HikariPool(this);
LOGGER.info("{} - Start completed.", configuration.getPoolName());
} /** {@inheritDoc} */
@Override
public Connection getConnection() throws SQLException
{
if (isClosed()) {
throw new SQLException("HikariDataSource " + this + " has been closed.");
} if (fastPathPool != null) {
return fastPathPool.getConnection();
} // See http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
HikariPool result = pool;
if (result == null) {
synchronized (this) {
result = pool;
if (result == null) {
validate();
LOGGER.info("{} - Starting...", getPoolName());
try {
pool = result = new HikariPool(this);
this.seal();
}
catch (PoolInitializationException pie) {
if (pie.getCause() instanceof SQLException) {
throw (SQLException) pie.getCause();
}
else {
throw pie;
}
}
LOGGER.info("{} - Start completed.", getPoolName());
}
}
} return result.getConnection();
}

springboot的autoconfig是采用BeanUtils的反射来初始化HikariDataSource,走的是默认构造器,因此校验就依赖set方法以及后续的getConnection方法。

PoolBase.setLoginTimeout

HikariCP-2.7.6-sources.jar!/com/zaxxer/hikari/pool/PoolBase.java

   /**
* Set the loginTimeout on the specified DataSource.
*
* @param dataSource the DataSource
*/
private void setLoginTimeout(final DataSource dataSource)
{
if (connectionTimeout != Integer.MAX_VALUE) {
try {
dataSource.setLoginTimeout(Math.max(1, (int) MILLISECONDS.toSeconds(500L + connectionTimeout)));
}
catch (Throwable e) {
LOGGER.info("{} - Failed to set login timeout for data source. ({})", poolName, e.getMessage());
}
}
}

这个在初始化的时候设定了loginTimeout,初始值为Math.max(1, (int) MILLISECONDS.toSeconds(500L + connectionTimeout))

springboot的HikariDataSource默认配置的默认值如下

name 构造器默认值 默认配置validate之后的值 validate重置
minIdle -1 10 minIdle<0或者minIdle>maxPoolSize,则被重置为maxPoolSize
maxPoolSize -1 10 如果maxPoolSize小于1,则会被重置。当minIdle<=0被重置为DEFAULT_POOL_SIZE则为10;如果minIdle>0则重置为minIdle的值
maxLifetime MINUTES.toMillis(30) = 1800000 1800000 如果不等于0且小于30秒则会被重置回30分钟
connectionTimeout SECONDS.toMillis(30) = 30000 30000 如果小于250毫秒,则被重置回30秒
validationTimeout SECONDS.toMillis(5) = 5000 5000 如果小于250毫秒,则会被重置回5秒
loginTimeout 10 30 Math.max(1, (int) MILLISECONDS.toSeconds(500L + connectionTimeout)),为connectionTimeout+500ms转为秒数取整 与 1 取最大者
idleTimeout MINUTES.toMillis(10) = 600000 600000 如果idleTimeout+1秒>maxLifetime 且 maxLifetime>0,则会被重置为0;如果idleTimeout!=0且小于10秒,则会被重置为10秒
leakDetectionThreshold 0 0 如果大于0且不是单元测试,则进一步判断:(leakDetectionThreshold < SECONDS.toMillis(2) or (leakDetectionThreshold > maxLifetime && maxLifetime > 0),会被重置为0 . 即如果要生效则必须>0,而且不能小于2秒,而且当maxLifetime > 0时不能大于maxLifetime
initializationFailTimeout 1 1 -
isAutoCommit true true -
isReadOnly false fasle -
isAllowPoolSuspension false false -
isIsolateInternalQueries false false -
isRegisterMbeans false false -
sealed false true 运行启动后这个标志为true,表示不再运行修改
poolName null HikariPool-1 -
catalog null null -
connectionInitSql null null -
connectionTestQuery null null -
dataSourceClassName null null -
schema null null -
transactionIsolationName null null -
dataSource null null -
dataSourceProperties {} {} -
threadFactory null null -
scheduledExecutor null null -
metricsTrackerFactory null null -
metricRegistry null null -
healthCheckRegistry null null -
healthCheckProperties {} {} -

doc

打赏

Spring-Boot-2.0.0-M1版本将默认的数据库连接池从tomcat jdbc pool改为了hikari的更多相关文章

  1. Spring Boot 2.1.0 已发布,7 个重大更新!

    距离<重磅:Spring Boot 2.0 正式发布!>已经过去大半年了,而 Spring Boot 2.1.0 在 10 月底就发布了,我们来看下 Spring Boot 2.1.0 都 ...

  2. (转)Spring Boot 2 (九):【重磅】Spring Boot 2.1.0 权威发布

    http://www.ityouknow.com/springboot/2018/11/03/spring-boot-2.1.html 如果这两天登录 https://start.spring.io/ ...

  3. 【重磅】Spring Boot 2.1.0 权威发布

    如果这两天登录 https://start.spring.io/ 就会发现,Spring Boot 默认版本已经升到了 2.1.0.这是因为 Spring Boot 刚刚发布了 2.1.0 版本,我们 ...

  4. Spring boot 2.1.0 -- swagger2 整合

    依赖版本信息 Spring boot 2.1.0.RELEASE swagger2 2.7.0 1. mvn 配置  pom.xml 包引入 <!--swagger2依赖--> <d ...

  5. Spring Boot 2.2.0,性能提升+支持Java13

    随着 Spring Framework 5.2.0 成功发布之后,Spring Boot 2.2 也紧跟其后,发布了第一个版本:2.2.0.下面就来一起来看看这个版本都更新了些什么值得我们关注的内容. ...

  6. Spring Boot 2.3.0正式发布:优雅停机、配置文件位置通配符新特性一览

    当大潮退去,才知道谁在裸泳..关注公众号[BAT的乌托邦]开启专栏式学习,拒绝浅尝辄止.本文 https://www.yourbatman.cn 已收录,里面一并有Spring技术栈.MyBatis. ...

  7. spring boot:redis+lua实现生产环境中可用的秒杀功能(spring boot 2.2.0)

    一,秒杀需要具备的功能: 秒杀通常是电商中用到的吸引流量的促销活动方式 搭建秒杀系统,需要具备以下几点: 1,限制每个用户购买的商品数量,(秒杀价格为吸引流量一般会订的很低,不能让一个用户全部抢购到手 ...

  8. spring boot:用redis+lua实现基于ip地址的分布式流量限制(限流/简单计数器算法)(spring boot 2.2.0)

    一,限流有哪些环节? 1,为什么要限流? 目的:通过对并发请求进行限速或者一个时间单位内的的请求进行限速,目的是保护系统可正常提供服务,避免被压力太大无法响应服务. 如果达到限制速率则可以采取预定的处 ...

  9. spring boot:用redis+lua实现表单接口的幂等性(spring boot 2.2.0)

    一,什么是幂等性? 1,幂等: 幂等操作:不管执行多少次,所产生的影响都和一次执行的影响相同. 幂等函数或幂等方法:可以使用相同的参数重复执行,并能获得相同的结果的函数/方法. 这些函数/方法不用担心 ...

随机推荐

  1. redis之master.slave主从复制

    简介 主机数据更新后根据配置和策略,自动同步到备机的master/slave机制,master以写为主,slave以读为主 从库配置 配置从库,不配主库 配置从库: 格式: slaveof 主库ip ...

  2. 「Spark」Spark SQL Thrift Server运行方式

    Spark SQL可以使用JDBC/ODBC或命令行接口充当分布式查询引擎.这种模式,用户或者应用程序可以直接与Spark SQL交互,以运行SQL查询,无需编写任何代码. Spark SQL提供两种 ...

  3. 【转】Makefile步步为营

    Makefile步步为营 本目录主要包含Makefile一步步递进学习的示例代码 makefile代码实例:https://www.lanzous.com/i9m9npi step0:Makefile ...

  4. java数据结构---循环队列

    #java学习经验总结------循环队列的实现(数组) package datastructure;/*数组实现循环队列 队列first in first out*/ public class Ci ...

  5. (未完成)【Android】MVP模式初见(一)

    最近在阅读郭霖大神的公众号时,分类中架构引起了我的注意. 虽然是个人开发(水平很菜的那种),但最终都要向企业正式项目开发靠近.因此接下来一段时间,主要学习一下MVP架构.Retrofit以及RxJav ...

  6. idea svn提交时,performing vcs refresh时间很长的解决办法

    解决方法:version control -> local changes -> local changelist 列表中无用的文件或文件夹右键选择svn忽略 ps:原因是文件太多,导致对 ...

  7. Ubuntu禁用root账号,开启Ubuntu密钥登录

    新建普通用户 ## 新建普通用户 $ adduser ubuntu $ apt-get install sudo ## 将用户加入sudo组 $ usermod -a -G sudo ubuntu 为 ...

  8. opencv —— morphologyEx 开运算、闭运算、形态学梯度、顶帽、黑帽

    开运算:先腐蚀后膨胀. 能够排除小亮点. 闭运算:先膨胀后腐蚀. 能够排除小黑点. 形态学梯度:膨胀图 — 腐蚀图. 对二值图像进行这一操作,可将图块的边缘突出出来,故可用来保留物体边缘轮廓. 顶帽: ...

  9. windows系统安装部署python3.5和python2.7双解释器并存

    前提材料准备: 下载对应版本的安装包:下载地址:https://www.python.org/downloads/windows/ python3.8.x安装包下载: python2.7.x安装包下载 ...

  10. Byte 一个字节的数据大小范围为什么是-128~127

    一个字节是8位,最高位是符号位,最高位为0则是正数.最高位为1则是负数 如果一个数是正数,最大数则为:01111111,转为十进制为127, 如果一个数是负数,按照一般人都会觉得是11111111,转 ...