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


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

    依赖:

    
                com.alibaba
                druid-spring-boot-starter
                ${druid.version}
    
    
        com.baomidou
        mybatis-plus-boot-starter
        ${mybatisplus.boot.version}
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    监控配置:
    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();
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    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
    
    • 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

    本地启动项目后,druid的地址为项目地址+druid,例如http://localhost:8888/platform-plus/druid,
    在这里插入图片描述
    上图就是yaml文件中的initial-size等配置。

  • 相关阅读:
    uni-app 之 vue位置怎样设置
    Webpack 复习小结
    前端js动态切换图片文字
    恒合仓库 - 采购单管理模块
    Android APP开机启动,安卓APP开发自启动,安卓启动后APP自动启动
    【大数据之Kafka】十五、Kafka-Kraft模式
    window11中设置环境变量与ftp服务器开启
    Linux中的man命令
    App加固中的代码混淆功能,让逆向工程师很头疼
    Qt中QJsonDocument 类
  • 原文地址:https://blog.csdn.net/qq_37713521/article/details/132969214