Druid是一个关系型数据库连接池,是阿里巴巴的一个开源项目,地址:https://github.com/alibaba/druid 。Druid不但提供连接池的功能,还提供监控功能,可以实时查看数据库连接池和SQL查询的工作情况。

本例使用Spring Boot 1.5 , mybatis

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>1.5.21.RELEASE</version>
  5. <relativePath/> <!-- lookup parent from repository -->
  6. </parent>
  7. <dependency>
  8. <groupId>org.mybatis.spring.boot</groupId>
  9. <artifactId>mybatis-spring-boot-starter</artifactId>
  10. <version>1.3.1</version>
  11. </dependency>
  12. 不同版本的Spring Boot和MyBatis版本对应可查看官方文档:http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/。

Spring Boot 1.5版本

Maven pom依赖

Druid为Spring Boot项目提供了对应的starter:

  1. <dependency>
  2. <groupId>mysql</groupId>
  3. <artifactId>mysql-connector-java</artifactId>
  4. </dependency>
  5. <dependency>
  6. <groupId>com.alibaba</groupId>
  7. <artifactId>druid-spring-boot-starter</artifactId>
  8. <version>1.1.6</version>
  9. </dependency>

.\resources\application.yml

  1. server:
  2. context-path: /web
  3. spring:
  4. datasource:
  5. druid:
  6. # 数据库访问配置, 使用druid数据源
  7. type: com.alibaba.druid.pool.DruidDataSource
  8. driver-class-name: com.mysql.jdbc.Driver
  9. url: jdbc:mysql://127.0.0.1:3306/YOUR_DB_NAME?useUnicode=true&characterEncoding=utf-8
  10. username: root
  11. password: root
  12. # 连接池配置
  13. initial-size: 5
  14. min-idle: 5
  15. max-active: 20
  16. # 连接等待超时时间
  17. max-wait: 30000
  18. # 配置检测可以关闭的空闲连接间隔时间
  19. time-between-eviction-runs-millis: 60000
  20. # 配置连接在池中的最小生存时间
  21. min-evictable-idle-time-millis: 300000
  22. validation-query: select '1' from dual
  23. test-while-idle: true
  24. test-on-borrow: false
  25. test-on-return: false
  26. # 打开PSCache,并且指定每个连接上PSCache的大小
  27. pool-prepared-statements: true
  28. max-open-prepared-statements: 20
  29. max-pool-prepared-statement-per-connection-size: 20
  30. # 配置监控统计拦截的filters, 去掉后监控界面sql无法统计, 'wall'用于防火墙
  31. filters: stat,wall
  32. # Spring监控AOP切入点,如x.y.z.service.*,配置多个英文逗号分隔
  33. aop-patterns: com.springboot.servie.*
  34. # WebStatFilter配置
  35. web-stat-filter:
  36. enabled: true
  37. # 添加过滤规则
  38. url-pattern: /*
  39. # 忽略过滤的格式
  40. exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'
  41. # StatViewServlet配置
  42. stat-view-servlet:
  43. enabled: true
  44. # 访问路径为/druid时,跳转到StatViewServlet
  45. url-pattern: /druid/*
  46. # 是否能够重置数据
  47. reset-enable: false
  48. # 需要账号密码才能访问控制台
  49. login-username: druid
  50. login-password: druid123
  51. # IP白名单
  52. # allow: 127.0.0.1
  53. # IP黑名单(共同存在时,deny优先于allow)
  54. # deny: 192.168.1.218
  55. # 配置StatFilter
  56. filter:
  57. stat:
  58. log-slow-sql: true

Spring Boot 添加Druid连接池(1.5 版本)的更多相关文章

  1. spring boot配置druid连接池连接mysql

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  2. Spring Boot下Druid连接池+mybatis

      目前Spring Boot中默认支持的连接池有dbcp,dbcp2, hikari三种连接池.  引言: 在Spring Boot下默认提供了若干种可用的连接池,Druid来自于阿里系的一个开源连 ...

  3. Spring Boot使用Druid连接池基本配置

    以下为Spring Boot配置Druid 一.pom.xml配置 <dependency> <groupId>com.alibaba</groupId> < ...

  4. Spring Boot下Druid连接池的使用配置分析

    https://blog.csdn.net/blueheart20/article/details/52384032

  5. Spring Boot [使用 Druid 数据库连接池]

    导读 最近一段时间比较忙,以至于很久没有更新Spring Boot系列文章,恰好最近用到Druid, 就将Spring Boot 使用 Druid作为数据源做一个简单的介绍. Druid介绍: Dru ...

  6. Spring Boot之默认连接池配置策略

    注意:如果我们使用spring-boot-starter-jdbc 或 spring-boot-starter-data-jpa “starters”坐标,Spring Boot将自动配置Hikari ...

  7. 深入理解Spring Boot数据源与连接池原理

    ​ Create by yster@foxmail.com 2018-8-2 一:开始 在使用Spring Boot数据源之前,我们一般会导入相关依赖.其中数据源核心依赖就是spring‐boot‐s ...

  8. Spring Boot集成Druid数据库连接池

    1. 前言 Druid数据库连接池由阿里巴巴开源,号称是java语言中最好的数据库连接池,是为监控而生的.Druid的官方地址是:https://github.com/alibaba/druid 通过 ...

  9. spring boot:配置druid数据库连接池(开启sql防火墙/使用log4j2做异步日志/spring boot 2.3.2)

    一,druid数据库连接池的功能? 1,Druid是阿里巴巴开发的号称为监控而生的数据库连接池 它的优点包括: 可以监控数据库访问性能 SQL执行日志 SQL防火墙 2,druid的官方站: http ...

随机推荐

  1. day1_python流程控制、For循环

    一.流程控制 条件语句 1.1.单分支 ? 1.2.多分支 ? 需求一.用户登陆验证 #!/usr/bin/env python name=input('请输入用户名字:') password=inp ...

  2. poj 2689 Prime Distance (素数二次筛法)

    2689 -- Prime Distance 没怎么研究过数论,还是今天才知道有素数二次筛法这样的东西. 题意是,要求求出给定区间内相邻两个素数的最大和最小差. 二次筛法的意思其实就是先将1~sqrt ...

  3. Pytorch使用GPU

    pytorch如何使用GPU在本文中,我将介绍简单如何使用GPU pytorch是一个非常优秀的深度学习的框架,具有速度快,代码简洁,可读性强的优点. 我们使用pytorch做一个简单的回归. 首先准 ...

  4. Python--day28--set去重

    set去重:set依赖对象hash eq

  5. centos linux mysql 10060远程错误代码

    Navicat for MySQL远程连接数据错误代码10060 1.登陆远程linux服务器命令界面 vim /etc/sysconfig/iptables  进入防火墙配置修改 增加以下两条防火墙 ...

  6. P1104 最大公约数和最小公倍数问题

    题目描述 输入2个正整数 \(x0, y0 (2 \le x0 \lt 100000, 2 \le y0 \le 1000000)\) ,求出满足下列条件的 P,Q 的个数. 条件: P,Q是正整数 ...

  7. P1041 查找元素

    题目描述 现在告诉你一个长度为 \(n\) 的有序数组 \(a_1, a_2, ..., a_n\) ,以及 \(q\) 次询问,每次询问会给你一个数 \(x\) ,对于每次询问,你需要确定在数组中是 ...

  8. JPA查询之Specification以及HQL、SQL查询

    1.Specification //查询条件List List<Predicate> predicateList = new ArrayList<Predicate>(); S ...

  9. 2019年7月20日针对iPhone7/7P有锁机的爆破限制

    背景 2019年7月20号苹果更改了激活策略,致使卡贴机一夜回到解放前,目前只能使用tmsi或者tmsi+iccid模式激活手机,但是缺点是移动联通信号真的不稳定,漏接电话,无法开启热点等等毛病.尤其 ...

  10. 响应式自适应布局代码,rem布局

    响应式自适应布局代码 首先是先设置根字体大小,PC端一般是16px为根字体,移动端会有不同的,根据情况来设置 js部分 document.querySelector('html').style.fon ...