基础配置: springboot2.x版本 jdk1.8
依赖:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatisplus.boot.version}</version>
</dependency>
监控配置:
Druid.config
package com.platform.config;
import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
@Configuration
public class DruidConfig {
@Bean
@ConfigurationProperties("spring.datasource.druid")
public DataSource druidDataSource(){
return new DruidDataSource();
}
}
yaml文件:
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
# 代码生成通过读取driverClassName来判断数据库类型
driverClassName: oracle.jdbc.driver.OracleDriver
druid:
first: #数据源1
url: jdbc:oracle:thin:@xxx:1526
username: xxx
password: xxx
initial-size: 10
max-active: 100
min-idle: 10
max-wait: 60000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
test-while-idle: true
test-on-borrow: false
test-on-return: false
filter:
stat:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
wall:
config:
multi-statement-allow: true
second: #数据源2
# 和数据源1相同
url: jdbc:oracle:thin:@xxx:1526
username: xxx
password: xxx
# 下面这个设置的druid的监控页面的登录密码等
stat-view-servlet:
enabled: true
url-pattern: /druid/*
login-username: druid
login-password: 123456
本地启动项目后,druid的地址为项目地址+druid,例如http://localhost:8888/platform-plus/druid,
上图就是yaml文件中的initial-size等配置。