zoukankan      html  css  js  c++  java
  • springboot 添加 mybatis 和 druid 依赖

    参照
    https://www.sevenyuan.cn/
    https://github.com/Vip-Augus/springboot-note
    2021最新版 SpringBoot 速记教程
    https://mp.weixin.qq.com/s/OnPd_-7InEUbGQxE3fzlIA

    一、添加 mybatis 和 druid 依赖

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>
    
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.18</version>
    </dependency>
    

    二、配置数据库和连接池参数

    # 数据库配置
    spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
    spring.datasource.username=root
    spring.datasource.password=12345678
    
    # druid 配置
    spring.datasource.druid.initial-size=5
    spring.datasource.druid.max-active=20
    spring.datasource.druid.min-idle=5
    spring.datasource.druid.max-wait=60000
    spring.datasource.druid.pool-prepared-statements=true
    spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20
    spring.datasource.druid.max-open-prepared-statements=20
    spring.datasource.druid.validation-query=SELECT 1
    spring.datasource.druid.validation-query-timeout=30000
    spring.datasource.druid.test-on-borrow=true
    spring.datasource.druid.test-on-return=false
    spring.datasource.druid.test-while-idle=false
    #spring.datasource.druid.time-between-eviction-runs-millis=
    #spring.datasource.druid.min-evictable-idle-time-millis=
    #spring.datasource.druid.max-evictable-idle-time-millis=10000
    
    # Druid stat filter config
    spring.datasource.druid.filters=stat,wall
    spring.datasource.druid.web-stat-filter.enabled=true
    spring.datasource.druid.web-stat-filter.url-pattern=/*
    # session 监控
    spring.datasource.druid.web-stat-filter.session-stat-enable=true
    spring.datasource.druid.web-stat-filter.session-stat-max-count=10
    spring.datasource.druid.web-stat-filter.principal-session-name=admin
    spring.datasource.druid.web-stat-filter.principal-cookie-name=admin
    spring.datasource.druid.web-stat-filter.profile-enable=true
    # stat 监控
    spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*
    spring.datasource.druid.filter.stat.db-type=mysql
    spring.datasource.druid.filter.stat.log-slow-sql=true
    spring.datasource.druid.filter.stat.slow-sql-millis=1000
    spring.datasource.druid.filter.stat.merge-sql=true
    spring.datasource.druid.filter.wall.enabled=true
    spring.datasource.druid.filter.wall.db-type=mysql
    spring.datasource.druid.filter.wall.config.delete-allow=true
    spring.datasource.druid.filter.wall.config.drop-table-allow=false
    
    # Druid manage page config
    spring.datasource.druid.stat-view-servlet.enabled=true
    spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*
    spring.datasource.druid.stat-view-servlet.reset-enable=true
    spring.datasource.druid.stat-view-servlet.login-username=admin
    spring.datasource.druid.stat-view-servlet.login-password=admin
    #spring.datasource.druid.stat-view-servlet.allow=
    #spring.datasource.druid.stat-view-servlet.deny=
    spring.datasource.druid.aop-patterns=cn.sevenyuan.demo.*
    

    通过上面的配置,我本地开启了三个页面的监控:SQL 、 URL 和 Sprint 监控,如下图:

    通过上面的配置,SpringBoot 很方便的就整合了 Druid 和 mybatis,同时根据在 properties 文件中配置的参数,开启了 Druid 的监控。
    http://localhost:8080/druid/login.html

  • 相关阅读:
    Hadoop安装教程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.04
    练oj时的小技巧(大多都在oj记录里,这是被忘记的部分)
    HDU 3032 (SG打表找规律)
    SG 大法(Sprague-Grundy函数)
    基于Linux的MySQL基本操作
    java.sql.SQLException: Unable to load authentication plugin ‘caching_sha2_password‘.解决方法
    手把手教你安装和配置MYSQL数据库
    理解Python闭包,这应该是最好的例子
    SQL基础
    MySQL令人咋舌的隐式转换
  • 原文地址:https://www.cnblogs.com/stubborn-dude/p/14428554.html
Copyright © 2011-2022 走看看