增加支持 profiles 配置; 区分 开发和生产环境 ;
增加druid数据库加密配置, 生产环境 数据库密码加密。
This commit is contained in:
parent
56c00e2589
commit
d248384b4f
|
|
@ -0,0 +1,63 @@
|
|||
# 数据源配置
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
druid:
|
||||
# 主库数据源
|
||||
master:
|
||||
url: jdbc:mysql://localhost:3316/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
# password: 123456
|
||||
password: SeO01Bk2qVa/Xw7NzBJ38tIvudlucuv5fat7tVsY05GT09L5C/sVcaMvaMCD/1g5k9oCEj/fBZ7z1+i48Gnvlg==
|
||||
# 从库数据源
|
||||
slave:
|
||||
# 从数据源开关/默认关闭
|
||||
enabled: false
|
||||
url:
|
||||
username:
|
||||
password:
|
||||
# 初始连接数
|
||||
initialSize: 5
|
||||
# 最小连接池数量
|
||||
minIdle: 10
|
||||
# 最大连接池数量
|
||||
maxActive: 20
|
||||
# 配置获取连接等待超时的时间
|
||||
maxWait: 60000
|
||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
timeBetweenEvictionRunsMillis: 60000
|
||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
minEvictableIdleTimeMillis: 300000
|
||||
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
||||
maxEvictableIdleTimeMillis: 900000
|
||||
# 配置检测连接是否有效
|
||||
validationQuery: SELECT 1 FROM DUAL
|
||||
testWhileIdle: true
|
||||
testOnBorrow: false
|
||||
testOnReturn: false
|
||||
webStatFilter:
|
||||
enabled: true
|
||||
statViewServlet:
|
||||
enabled: true
|
||||
# 设置白名单,不填则允许所有访问
|
||||
allow:
|
||||
url-pattern: /druid/*
|
||||
# 控制台管理用户名和密码
|
||||
login-username: ruoyi
|
||||
login-password: 123456
|
||||
filter:
|
||||
stat:
|
||||
enabled: true
|
||||
# 慢SQL记录
|
||||
log-slow-sql: true
|
||||
slow-sql-millis: 1000
|
||||
merge-sql: true
|
||||
wall:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
# 启用数据库解密 【boot druid加密】
|
||||
filters: config
|
||||
connectionProperties: config.decrypt=true;config.decrypt.key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAM+j76P6vjNr3ryECDjiQ0KoD35TZO1y75xvPY37okhUzfExTQVatlcLeK9pG8PxpMiIFa5JwKhwVD+sg/ocUDcCAwEAAQ==
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# \u6d4b\u8bd5\uff0c properties \u6587\u4ef6\u4f18\u5148\u7ea7\u9ad8\u4e8e yml\u6587\u4ef6
|
||||
ruoyi.version=5.1.0
|
||||
|
||||
# spring profiles \u914d\u7f6e\u3002 druid \u5f00\u53d1\u73af\u5883\uff1bdruid-pro \u751f\u4ea7\u73af\u5883
|
||||
spring.profiles.active=druid
|
||||
|
||||
|
|
@ -1,7 +1,13 @@
|
|||
package com.ruoyi.framework.config.properties;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +51,9 @@ public class DruidProperties
|
|||
@Value("${spring.datasource.druid.testOnReturn}")
|
||||
private boolean testOnReturn;
|
||||
|
||||
@Resource
|
||||
private Environment environment ;
|
||||
|
||||
public DruidDataSource dataSource(DruidDataSource datasource)
|
||||
{
|
||||
/** 配置初始化大小、最小、最大 */
|
||||
|
|
@ -72,6 +81,16 @@ public class DruidProperties
|
|||
datasource.setTestOnBorrow(testOnBorrow);
|
||||
/** 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。 */
|
||||
datasource.setTestOnReturn(testOnReturn);
|
||||
|
||||
String filters = environment.getProperty("spring.datasource.druid.filters");
|
||||
try {
|
||||
datasource.setFilters(filters);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String connectionProperties = environment.getProperty("spring.datasource.druid.connectionProperties");
|
||||
datasource.setConnectionProperties(connectionProperties);
|
||||
|
||||
return datasource;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue