Spring Boot 2.0 集成 Druid 数据源
一、Maven项目依赖
<!-- 开发者工具(热部署 修改classpath下的文件springboot自动重启) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> <!-- Web场景启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency> <!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency> <!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<scope>runtime</scope>
</dependency> <!-- SpringBoot测试依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
二、配置文件
由于使用了SpringBoot,所以大部分不需要我们手动配置,只需要进行简单的指定数据源等必要的配置:
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.druid.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.url=jdbc:mysql://172.xx.xx.26:3306/risk?useUnicode=true&characterEncoding=utf-8
spring.datasource.druid.username=root
spring.datasource.druid.password=123456
# 初始化时建立的连接数
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.time-between-eviction-runs-millis=60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
spring.datasource.druid.min-evictable-idle-time-millis=300000
# 是否缓存preparedStatement
spring.datasource.druid.pool-prepared-statements=true
# 最大preparedStatement缓存数,当pool-prepared-statements=true时需要大于0
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20
# 检测连接是否失效的sql
spring.datasource.druid.validation-query=SELECT 'x'
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
spring.datasource.druid.filters=wall,stat
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=3000 # WebStatFilter配置,说明请参考Druid Wiki,配置_配置WebStatFilter
spring.datasource.druid.web-stat-filter.enabled=true
spring.datasource.druid.web-stat-filter.url-pattern=/*
spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*
spring.datasource.druid.web-stat-filter.session-stat-enable=false
spring.datasource.druid.web-stat-filter.session-stat-max-count=1000 # StatViewServlet配置:展示Druid的统计信息,StatViewServlet的用途包括:1.提供监控信息展示的html页面2.提供监控信息的JSON API
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
三、测试
在配置中,我们把监控平台的路径设置为/druid/*,用户和密码为:admin/admin
http://localhost:8080/xxxx/druid/login.html


Spring Boot 2.0 集成 Druid 数据源的更多相关文章
- 14、Spring Boot 2.x 集成 Druid 数据源
14.Spring Boot 2.x 集成 Druid 数据源 完整源码: Spring-Boot-Demos
- Spring Boot HikariCP 一 ——集成多数据源
其实这里介绍的东西主要是参考的另外一篇文章,数据库读写分离的. 参考文章就把链接贴出来,里面有那位的代码,简单明了https://gitee.com/comven/dynamic-datasource ...
- spring boot 2.0 集成 shiro 和 pac4j cas单点登录
新开的项目,果断使用 spring boot 最新版本 2.0.3 ,免得后期升级坑太多,前期把雷先排了. 由于对 shiro 比较熟,故使用 shiro 来做权限控制.同时已经存在了 cas ...
- spring boot 2.0 配置双数据源 MySQL 和 SqlServer
参考:https://www.cnblogs.com/xiaofengfeng/p/9552816.html 安装 org.mybatis.spring.boot:mybatis-spring-boo ...
- Spring boot 集成 Druid 数据源
Druid是阿里开源的一个JDBC应用组件,其中包括三部分: DruidDriver:代理Driver,能够提供基于Filter-Chain模式的插件体系. DruidDataSource:高效可管理 ...
- Spring Boot:集成Druid数据源
综合概述 数据库连接池负责分配.管理和释放数据库连接,它允许应用程序重复使用一个现有的数据库连接,而不是再重新建立一个:释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数据库连接而引起的数据 ...
- Spring Boot 整合 Mybatis 实现 Druid 多数据源详解
摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! “清醒时做事,糊涂时跑步,大怒时睡觉,独处时思考” 本文提纲一.多数据源的应用场景二.运行 sp ...
- Spring Boot 2.0(八):Spring Boot 集成 Memcached
Memcached 介绍 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态.数据库驱动网站 ...
- Spring Boot 2.0 的快速入门(图文教程)
摘要: 原创出处 https://www.bysocket.com 「公众号:泥瓦匠BYSocket 」欢迎关注和转载,保留摘要,谢谢! Spring Boot 2.0 的快速入门(图文教程) 大家都 ...
随机推荐
- P5657 格雷码
思路 考场上的递归思路 每次向下递归的时候判断是左半边还是右半边即可 注意向右半边递归之后下一层序列要反转过来即可 代码 #include <cstdio> #include <al ...
- sentinel.conf 配置
daemonize yes logfile "/home/data/redis/redis_sentinel.log" sentinel monitor mymaster 192. ...
- MultipartFile类
MultipartFile类常用的一些方法: String getContentType()//获取文件MIME类型InputStream getInputStream()//后去文件流String ...
- [Nx] Note for learning Nx
Proxy configuration: When we have already fews applications running in the workspace, and we want to ...
- ISCSI共享存储
ISCSI网络磁盘 默认端口:3260 服务端: 一. 二.安装软件:targetcli 用命令targetcli进行配置------------------------进入iscsi磁盘配置模 ...
- python第三方库安装
如安装jieba分词库 代码对Python 2/3均兼容 全自动安装:easy_install jieba或者pip install jieba / pip3 install jieba 半自动安装: ...
- (六)绘图,文本编程,定时器,菜单,图标icon,消息类型
1,简单绘图 画直线 a,鼠标按下和抬起 void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代 ...
- hdu 6021 MG loves string (一道容斥原理神题)(转)
MG loves string Accepts: 30 Submissions: 67 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- 2017.9.23 NOIP2017 金秋杯系列模拟赛 day1 T1
回形遍历( calc .cpp/c/pas) 时间限制:1s内存 限制: 256MB [问题 描 述] 给出一个 n*m 的棋盘,按如下方式遍历,请问(x,y)往后 z 步走到的是哪个格子. [输入] ...
- Linux创建删除文件和文件夹
要想删除和创建,需要有root权限 [xwg@bogon ~]$ su root密码:[root@bogon xwg]# cd /home/a 切换到目录a[root@bogon a]# t ...