mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-09-21 21:06:39 +08:00
Pre Merge pull request !72 from Engineer/master
This commit is contained in:
commit
14a94a8ad1
@ -15,8 +15,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class DynamicDataSourceContextHandler {
|
||||
|
||||
/**
|
||||
* 使用ThreadLocal维护变量,ThreadLocal为每个使用该变量的线程提供独立的变量副本,
|
||||
* 所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本。
|
||||
* 使用ThreadLocal维护变量 ThreadLocal为每个使用该变量的线程提供独立的变量副本
|
||||
* 所以每一个线程都可以独立地改变自己的副本 而不会影响其它线程所对应的副本
|
||||
*/
|
||||
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
|
||||
|
||||
|
@ -1,9 +1,15 @@
|
||||
package net.lab1024.sa.base.properties;
|
||||
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Druid 配置属性
|
||||
*
|
||||
@ -13,6 +19,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @Email lab1024@163.com
|
||||
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class DruidProperties {
|
||||
|
||||
@ -43,6 +50,9 @@ public class DruidProperties {
|
||||
@Value("${spring.datasource.druid.max-evictable-idle-time-millis}")
|
||||
private int maxEvictableIdleTimeMillis;
|
||||
|
||||
@Value("${spring.datasource.druid.filters}")
|
||||
private String filters;
|
||||
|
||||
/**
|
||||
* 构建datasource
|
||||
*/
|
||||
@ -68,6 +78,24 @@ public class DruidProperties {
|
||||
// 配置一个连接在池中最小、最大生存的时间,单位是毫秒
|
||||
datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
|
||||
datasource.setMaxEvictableIdleTimeMillis(maxEvictableIdleTimeMillis);
|
||||
|
||||
datasource.setValidationQuery("SELECT 1");
|
||||
|
||||
try {
|
||||
// 配置过滤器
|
||||
datasource.setFilters(filters);
|
||||
|
||||
// 配置监控
|
||||
ArrayList<Filter> arrayList = new ArrayList<>();
|
||||
StatFilter statFilter = new StatFilter();
|
||||
statFilter.setMergeSql(true);
|
||||
statFilter.setSlowSqlMillis(1000);
|
||||
statFilter.setLogSlowSql(true);
|
||||
arrayList.add(statFilter);
|
||||
datasource.setProxyFilters(arrayList);
|
||||
} catch (SQLException e) {
|
||||
log.error("初始化数据源出错", e);
|
||||
}
|
||||
return datasource;
|
||||
}
|
||||
}
|
||||
|
@ -4,15 +4,18 @@ spring:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||
druid:
|
||||
# 主数据源
|
||||
master:
|
||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: SmartAdmin666
|
||||
password: root
|
||||
# 从数据源
|
||||
slave:
|
||||
enabled: true
|
||||
enabled: false
|
||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3_slave?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: SmartAdmin666
|
||||
password: root
|
||||
# 连接池配置
|
||||
initial-size: 2
|
||||
min-idle: 2
|
||||
max-active: 10
|
||||
@ -23,10 +26,16 @@ spring:
|
||||
min-evictable-idle-time-millis: 300000
|
||||
max-evictable-idle-time-millis: 300000
|
||||
filters: stat
|
||||
username: druid
|
||||
password: 1024
|
||||
login:
|
||||
enabled: false
|
||||
# Druid监控
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
login-username: druid
|
||||
login-password: 1024
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
|
||||
method:
|
||||
pointcut: net.lab1024.sa..*Service.*
|
||||
|
||||
|
@ -1,22 +1,41 @@
|
||||
spring:
|
||||
# 数据库连接信息
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||
druid:
|
||||
# 主数据源
|
||||
master:
|
||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: SmartAdmin666
|
||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||
password: root
|
||||
# 从数据源
|
||||
slave:
|
||||
enabled: false
|
||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3_slave?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
# 连接池配置
|
||||
initial-size: 2
|
||||
min-idle: 2
|
||||
max-active: 10
|
||||
max-wait: 60000
|
||||
connect-timeout: 30000
|
||||
socket-timeout: 30000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
max-evictable-idle-time-millis: 300000
|
||||
filters: stat
|
||||
druid:
|
||||
username: druid
|
||||
password: 1024
|
||||
login:
|
||||
enabled: false
|
||||
# Druid监控
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
login-username: druid
|
||||
login-password: 1024
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
|
||||
method:
|
||||
pointcut: net.lab1024.sa..*Service.*
|
||||
|
||||
|
@ -1,22 +1,41 @@
|
||||
spring:
|
||||
# 数据库连接信息
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:3306/smart_admin_v3?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||
druid:
|
||||
# 主数据源
|
||||
master:
|
||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: SmartAdmin666
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
initial-size: 10
|
||||
min-idle: 10
|
||||
max-active: 100
|
||||
password: root
|
||||
# 从数据源
|
||||
slave:
|
||||
enabled: false
|
||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3_slave?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
# 连接池配置
|
||||
initial-size: 2
|
||||
min-idle: 2
|
||||
max-active: 10
|
||||
max-wait: 60000
|
||||
connect-timeout: 30000
|
||||
socket-timeout: 30000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
max-evictable-idle-time-millis: 300000
|
||||
filters: stat
|
||||
druid:
|
||||
username: druid
|
||||
password: 1024lab
|
||||
login:
|
||||
enabled: false
|
||||
# Druid监控
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
login-username: druid
|
||||
login-password: 1024
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
|
||||
method:
|
||||
pointcut: net.lab1024.sa..*Service.*
|
||||
|
||||
|
@ -1,22 +1,41 @@
|
||||
spring:
|
||||
# 数据库连接信息
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||
druid:
|
||||
# 主数据源
|
||||
master:
|
||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: SmartAdmin666
|
||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||
password: root
|
||||
# 从数据源
|
||||
slave:
|
||||
enabled: false
|
||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3_slave?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: root
|
||||
# 连接池配置
|
||||
initial-size: 2
|
||||
min-idle: 2
|
||||
max-active: 10
|
||||
max-wait: 60000
|
||||
connect-timeout: 30000
|
||||
socket-timeout: 30000
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
max-evictable-idle-time-millis: 300000
|
||||
filters: stat
|
||||
druid:
|
||||
username: druid
|
||||
password: 1024
|
||||
login:
|
||||
enabled: false
|
||||
# Druid监控
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
login-username: druid
|
||||
login-password: 1024
|
||||
web-stat-filter:
|
||||
enabled: true
|
||||
url-pattern: /*
|
||||
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
|
||||
method:
|
||||
pointcut: net.lab1024.sa..*Service.*
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user