BlueXIII's Blog

热爱技术,持续学习

0%

Druid双数据源监控

参考文档

Nacos配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
spring:
datasource:
loginTimeout: 20
druid:
filter:
stat:
merge-sql: true
slow-sql-millis: 5000
web-stat-filter:
enabled: true
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
session-stat-enable: true
session-stat-max-count: 100
stat-view-servlet:
enabled: true
allow: ""
url-pattern: /druid/*
reset-enable: true
login-username: admin
login-password: yourpass
primary:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://10.193.2.8:3306/efpx_dubhe_quality?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: yourpass
driver-class-name: com.mysql.jdbc.Driver
initialSize: 5
maxActive: 20
minIdle: 5
maxWait: 10000
poolPreparedStatements: false
maxPoolPreparedStatementPerConnectionSize: -1
validationQuery: SELECT 'x'
testOnBorrow: false
testOnReturn: false
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 30000
filters: stat,wall,log4j2
warehouse:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://10.193.2.8:4000/warehouse?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&useSSL=false
username: root
password: yourpass
initialSize: 5
maxActive: 20
minIdle: 5
maxWait: 10000
poolPreparedStatements: false
maxPoolPreparedStatementPerConnectionSize: -1
validationQuery: SELECT 'x'
testOnBorrow: false
testOnReturn: false
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 30000
filters: stat,wall,log4j2

Bean配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.sdecloud.efpx.quality.biz.config;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
* JdbcTemplate配置类
*
* @author bluexiii
*/
@Configuration
public class JdbcTemplateConfiguration {
@Primary
@Bean(name = "dataSource")
@ConfigurationProperties("spring.datasource.primary")
public DataSource dataSource() {
return DruidDataSourceBuilder.create().build();
}

@Bean(name = "warehouseDataSource")
@ConfigurationProperties("spring.datasource.warehouse")
public DataSource warehouseDataSource() {
return DruidDataSourceBuilder.create().build();
}

@Bean("warehouseJdbcTemplate")
public JdbcTemplate warehouseJdbcTemplate(@Qualifier("warehouseDataSource") DataSource warehouseDataSource) {
return new JdbcTemplate(warehouseDataSource);
}
}