1、druid简介

Druid首先是一个数据库连接池。Druid是目前最好的数据库连接池,在功能、性能、扩展性方面,都超过其他数据库连接池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。
Druid充当数据库连接池,可以监控数据库访问性能,可以获得SQL执行日志

2、配置

  加入druid相关配置(.yml配置文件)

spring:
#数据库配置
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/springboot?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
username: root
password: root
druid:
# 初始连接数
initial-size: 10
# 最大连接池数量
max-active: 100
# 最小连接池数量
min-idle: 10
# 配置获取连接等待超时的时间
max-wait: 60000
# 打开PSCache,并且指定每个连接上PSCache的大小
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
validation-query: SELECT 1 FROM DUAL
test-while-idle: true
test-on-borrow: false
test-on-return: false
stat-view-servlet:
enabled: true
url-pattern: /druid/*
filter:
stat:
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: false
wall:
config:
multi-statement-allow: true

  

  引入druid依赖

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>

项目启动后可通过show processlist查看mysql的全部线程是否和配置的initial-size一致。

3、druid监控测试

访问ip:port/druid验证即可,url中的/druid要和配置文件中的url-pattern一致

stat-view-servlet:
enabled: true
url-pattern: /druid/*

效果如下:

具体源码参照:【Springboot集成Druid】

springboot 集成druid的更多相关文章

  1. SpringBoot Druid整合,SpringBoot 集成Druid

    SpringBoot Druid整合,SpringBoot 集成Druid ================================ ©Copyright 蕃薯耀 2018年4月8日 http ...

  2. 【Java】Springboot集成Druid

    Springboot集成Druid方案:一个是在POM中直接配置druid-spring-boot-starter,不用写任何代码:一个是配置druid,写几行代码,可以加入:在方案一基础上加入sta ...

  3. MyBatis初级实战之三:springboot集成druid

    OpenWrite版: 欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kuber ...

  4. SpringBoot集成druid数据库连接池的简单使用

    简介 Druid是阿里巴巴旗下Java语言中最好的数据库连接池.Druid能够提供强大的监控和扩展功能. 官网: https://github.com/alibaba/druid/wiki/常见问题 ...

  5. springboot集成druid+mybatis连接oracle数据库

    2.1.配置 druid 数据源 2. 随后要进行druid 的数据源的配置,如果要想使用druid 的数据源,那么首先一定要去修改 pom.xml 配置文件,引入以下包: oracle官网下载 oj ...

  6. springboot集成druid连接池

    使用druid连接池主要有几步: 1.添加jar和依赖 <groupId>org.mybatis.spring.boot</groupId> <artifactId> ...

  7. SpringBoot集成Druid实现监控

    application.properties文件完整信息 #连接数据库 spring.datasource.driver-class-name=org.mariadb.jdbc.Driver spri ...

  8. SpringBoot集成Druid

    maven <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-b ...

  9. springboot 集成 druid mybatis-plus

    通过这篇配置成功: https://www.cnblogs.com/shine-rainbow/p/9618100.html 不过 mybatis 3.4.6 一直maven下载失败,于是直接在官方那 ...

随机推荐

  1. 怎样用QT在windows环境通过编程卸载installShield打包的程序

    通常情况下,如果是一个完备的软件,我们可以通过启动软件的uninstaller.exe之类的程序来完成卸载.但是使用installShield打包的程序,本身可能并不含有这类卸载程序.此时,我们可以通 ...

  2. Badboy录制模式

    参考: http://leafwf.blog.51cto.com/872759/1109940 http://www.51testing.com/html/00/130600-1367743.html ...

  3. codeforce978C-Almost Arithmetic Progression+暴力,枚举前两个数字的情况

    传送门:http://codeforces.com/contest/978/problem/D 题意:求变为等差数列,最小要改动的数字个数: 思路:暴力,这道题只用枚举前面两个数字的情况就ok,反思自 ...

  4. Trace 2018徐州icpc网络赛 思维+二分

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy) ...

  5. POJ 2643 Election map

    POJ 2643 Election 第一次写博客,想通过写博客记录自己的ACM历程,也想解释下英文题目,写些自己的理解.也可以让自己以后找题目更加方便点嘛.ElectionTime Limit: 10 ...

  6. codeforces 808 E. Selling Souvenirs (dp+二分+思维)

    题目链接:http://codeforces.com/contest/808/problem/E 题意:最多有100000个物品最大能放下300000的背包,每个物品都有权值和重量,为能够带的最大权值 ...

  7. 全网最实用的 Debug调试技巧汇总-Python大佬偷偷使用的神技

    一.思考❓❔ 1.什么是debug? 找茬 找软件的茬 发现程序的缺陷 2.为什么需要debug? 谁都不敢保证,写的代码没有任何问题 高效查找软件异常 一位优秀的开发工程师 20%的时间写代码 80 ...

  8. 时间复杂度big-O、Big-Omega和big-Theta

    我们有三种曲线:   A curve that we know is "above" the running time function when n is large. ( Bi ...

  9. lambda表达式不同对象根据对象某个属性去重

    1.有时候有两个list对象,我们想要去重,比如: List<User> userList和List<Person>personList 想通过User的id和Person的i ...

  10. Redis常用命令(Set、Hash、Zset)

    1.Set(单值多value) 1. sadd.smembers key . > SADD set01 (integer) > SMEMBERS set01 ) " ) &quo ...