Detailed parameter description
configure | Default value | illustrate |
name | The significance of configuring this property is that if there are multiple data sources, they can be distinguished by name when monitoring. If there is no configuration, a name will be generated in the format: "DataSource-" + System.identityHashCode(this) |
|
jdbcUrl | The url to connect to the database is different for different databases. For example: mysql : jdbc:mysql://10.20.153.104:3306/druid2 oracle : jdbc:oracle:thin:@10.20.149.85:1521:ocnauto |
|
username | Username to connect to the database | |
password | Password to connect to the database. If you don't want the password to be written directly in the configuration file, you can use ConfigFilter. See here for details: https://github.com/alibaba/druid/wiki/%E4%BD%BF%E7%94%A8ConfigFilter |
|
driverClassName | Automatically identify by url | This item can be matched or not. If druid is not configured, the dbType will be automatically recognized according to the url, and then the corresponding driverClassName will be selected. |
initialSize | 0 | The number of physical connections established during initialization. Initialization occurs when the init method is explicitly called, or the first time getConnection |
maxActive | 8 | Maximum number of connection pools |
maxIdle | 8 | It is no longer used, and the configuration has no effect |
minIdle | Minimum number of connection pools | |
maxWait | The maximum wait time when getting a connection, in milliseconds. After maxWait is configured, fair locks are enabled by default, and the concurrency efficiency will decrease. If necessary, you can use unfair locks by configuring the useUnfairLock property to true. |
|
halfPreparedStatements | false | Whether to cache preparedStatement, which is PSCache. PSCache greatly improves the performance of databases that support cursors, such as oracle. There is no PSCache function in versions below mysql5.5, it is recommended to close it. Version 5.5 and above has PSCache, it is recommended to enable it. |
maxOpenPreparedStatements | -1 | To enable PSCache, it must be configured with a value greater than 0. When greater than 0, poolPreparedStatements is automatically triggered and modified to true. In Druid, there is no problem that PSCache under Oracle occupies too much memory, you can configure this value to be larger, such as 100 |
validationQuery | The sql used to detect whether the connection is valid requires a query statement. If the validationQuery is null, testOnBorrow, testOnReturn, testWhileIdle will not work. |
|
testOnBorrow | true | When applying for a connection, execute the validationQuery to check whether the connection is valid. This configuration will reduce performance. |
testOnReturn | false | When returning the connection, execute the validationQuery to check whether the connection is valid. This configuration will reduce performance. |
testWhileIdle | false | 建议配置为true,不影响性能,并且保证安全性。 申请连接的时候检测,如果空闲时间大于 timeBetweenEvictionRunsMillis, 执行validationQuery检测连接是否有效。 |
timeBetweenEvictionRunsMillis | 有两个含义: 1) Destroy线程会检测连接的间隔时间 2) testWhileIdle的判断依据,详细看testWhileIdle属性的说明 |
|
numTestsPerEvictionRun | 不再使用,一个DruidDataSource只支持一个EvictionRun | |
minEvictableIdleTimeMillis | ||
connectionInitSqls | 物理连接初始化的时候执行的sql | |
exceptionSorter | 根据dbType自动识别 | 当数据库抛出一些不可恢复的异常时,抛弃连接 |
filters | 属性类型是字符串,通过别名的方式配置扩展插件, 常用的插件有: 监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall |
|
proxyFilters | 类型是List<com.alibaba.druid.filter.Filter>, 如果同时配置了filters和proxyFilters, 是组合关系,并非替换关系 |