springboot druid多数据源配置,及druid监控

基础配置: springboot2.x版本 jdk1.8

依赖:


            com.alibaba
            druid-spring-boot-starter
            ${druid.version}


    com.baomidou
    mybatis-plus-boot-starter
    ${mybatisplus.boot.version}

监控配置:
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,
springboot druid多数据源配置,及druid监控_第1张图片
上图就是yaml文件中的initial-size等配置。

你可能感兴趣的:(spring,boot,后端,java)