-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
297 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 115 additions & 32 deletions
147
.../ruoyi-framework/src/main/java/com/ruoyi/framework/config/properties/DruidProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,174 @@ | ||
package com.ruoyi.framework.config.properties; | ||
|
||
import com.alibaba.druid.pool.DruidDataSource; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* druid 配置属性 | ||
* | ||
* @author ruoyi | ||
*/ | ||
@Configuration | ||
public class DruidProperties { | ||
|
||
public static final String DRUID_PREFIX_KEY = "spring.datasource.druid."; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "initialSize}") | ||
private int initialSize; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "minIdle}") | ||
private int minIdle; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "maxActive}") | ||
private int maxActive; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "maxWait}") | ||
private int maxWait; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "connectTimeout}") | ||
private int connectTimeout; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "socketTimeout}") | ||
private int socketTimeout; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "timeBetweenEvictionRunsMillis}") | ||
private int timeBetweenEvictionRunsMillis; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "minEvictableIdleTimeMillis}") | ||
private int minEvictableIdleTimeMillis; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "maxEvictableIdleTimeMillis}") | ||
private int maxEvictableIdleTimeMillis; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "validationQuery}") | ||
private String validationQuery; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "testWhileIdle}") | ||
private boolean testWhileIdle; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "testOnBorrow}") | ||
private boolean testOnBorrow; | ||
|
||
@Value("${" + DRUID_PREFIX_KEY + "testOnReturn}") | ||
private boolean testOnReturn; | ||
|
||
public DruidDataSource dataSource(DruidDataSource datasource) { | ||
/** 配置初始化大小、最小、最大 */ | ||
public void configureDataSource(DruidDataSource datasource) { | ||
// 配置初始化大小、最小、最大 | ||
datasource.setInitialSize(initialSize); | ||
datasource.setMaxActive(maxActive); | ||
datasource.setMinIdle(minIdle); | ||
|
||
/** 配置获取连接等待超时的时间 */ | ||
// 配置获取连接等待超时的时间 | ||
datasource.setMaxWait(maxWait); | ||
|
||
/** 配置驱动连接超时时间,检测数据库建立连接的超时时间,单位是毫秒 */ | ||
// 配置驱动连接超时时间,检测数据库建立连接的超时时间,单位是毫秒 | ||
datasource.setConnectTimeout(connectTimeout); | ||
|
||
/** 配置网络超时时间,等待数据库操作完成的网络超时时间,单位是毫秒 */ | ||
// 配置网络超时时间,等待数据库操作完成的网络超时时间,单位是毫秒 | ||
datasource.setSocketTimeout(socketTimeout); | ||
|
||
/** 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 */ | ||
// 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 | ||
datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); | ||
|
||
/** 配置一个连接在池中最小、最大生存的时间,单位是毫秒 */ | ||
// 配置一个连接在池中最小、最大生存的时间,单位是毫秒 | ||
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); | ||
datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis); | ||
|
||
/** | ||
* 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用。 | ||
*/ | ||
// 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用 | ||
datasource.setValidationQuery(validationQuery); | ||
/** 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。 */ | ||
// 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效 | ||
datasource.setTestWhileIdle(testWhileIdle); | ||
/** 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ | ||
// 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能 | ||
datasource.setTestOnBorrow(testOnBorrow); | ||
/** 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */ | ||
// 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能 | ||
datasource.setTestOnReturn(testOnReturn); | ||
return datasource; | ||
} | ||
|
||
public int getInitialSize() { | ||
return initialSize; | ||
} | ||
|
||
public void setInitialSize(int initialSize) { | ||
this.initialSize = initialSize; | ||
} | ||
|
||
public int getMinIdle() { | ||
return minIdle; | ||
} | ||
|
||
public void setMinIdle(int minIdle) { | ||
this.minIdle = minIdle; | ||
} | ||
|
||
public int getMaxActive() { | ||
return maxActive; | ||
} | ||
|
||
public void setMaxActive(int maxActive) { | ||
this.maxActive = maxActive; | ||
} | ||
|
||
public int getMaxWait() { | ||
return maxWait; | ||
} | ||
|
||
public void setMaxWait(int maxWait) { | ||
this.maxWait = maxWait; | ||
} | ||
|
||
public int getConnectTimeout() { | ||
return connectTimeout; | ||
} | ||
|
||
public void setConnectTimeout(int connectTimeout) { | ||
this.connectTimeout = connectTimeout; | ||
} | ||
|
||
public int getSocketTimeout() { | ||
return socketTimeout; | ||
} | ||
|
||
public void setSocketTimeout(int socketTimeout) { | ||
this.socketTimeout = socketTimeout; | ||
} | ||
|
||
public int getTimeBetweenEvictionRunsMillis() { | ||
return timeBetweenEvictionRunsMillis; | ||
} | ||
|
||
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis) { | ||
this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis; | ||
} | ||
|
||
public int getMinEvictableIdleTimeMillis() { | ||
return minEvictableIdleTimeMillis; | ||
} | ||
|
||
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) { | ||
this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis; | ||
} | ||
|
||
public int getMaxEvictableIdleTimeMillis() { | ||
return maxEvictableIdleTimeMillis; | ||
} | ||
|
||
public void setMaxEvictableIdleTimeMillis(int maxEvictableIdleTimeMillis) { | ||
this.maxEvictableIdleTimeMillis = maxEvictableIdleTimeMillis; | ||
} | ||
|
||
public String getValidationQuery() { | ||
return validationQuery; | ||
} | ||
|
||
public void setValidationQuery(String validationQuery) { | ||
this.validationQuery = validationQuery; | ||
} | ||
|
||
public boolean isTestWhileIdle() { | ||
return testWhileIdle; | ||
} | ||
|
||
public void setTestWhileIdle(boolean testWhileIdle) { | ||
this.testWhileIdle = testWhileIdle; | ||
} | ||
|
||
public boolean isTestOnBorrow() { | ||
return testOnBorrow; | ||
} | ||
|
||
public void setTestOnBorrow(boolean testOnBorrow) { | ||
this.testOnBorrow = testOnBorrow; | ||
} | ||
|
||
public boolean isTestOnReturn() { | ||
return testOnReturn; | ||
} | ||
|
||
public void setTestOnReturn(boolean testOnReturn) { | ||
this.testOnReturn = testOnReturn; | ||
} | ||
|
||
} |
Oops, something went wrong.