Springboot整合druid
Springboot整合druid
application.yml
# 此处用来配置数据库
spring:
datasource:
url: jdbc:mysql://192.168.0.169:3306/jpa
username: root
password: xiaoyan
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
# 下面为连接池的补充设置,应用到上面所有数据源中, 可以写, 可以不写
# 初始化大小,最小,最大
initialSize: 5
minIdle: 5
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
DruidConfig
@Configuration
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druid() {
return new DruidDataSource();
}
@Bean
public ServletRegistrationBean<StatViewServlet> statViewServlet() {
ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>();
registrationBean.setServlet(new StatViewServlet());
registrationBean.setUrlMappings(Collections.singletonList("/druid/*"));
//设置初始化参数
Map<String, String> initMap = new HashMap<>();
// 登录账户密码
initMap.put("loginUsername", "admin");
initMap.put("loginPassword", "123456");
initMap.put("allow", "");
initMap.put("deny", "");
registrationBean.setInitParameters(initMap);
return registrationBean;
}
@Bean
public FilterRegistrationBean<WebStatFilter> webStatFilter() {
FilterRegistrationBean<WebStatFilter> registrationBean = new FilterRegistrationBean<>();
registrationBean.setFilter(new WebStatFilter());
registrationBean.setUrlPatterns(Collections.singletonList("/*"));
//设置初始化参数
Map<String, String> initMap = new HashMap<>(1);
initMap.put("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
registrationBean.setInitParameters(initMap);
return registrationBean;
}
}
数据监控地址:http://localhost:8080/druid

Springboot整合druid的更多相关文章
- SpringBoot整合Druid数据连接池
SpringBoot整合Druid数据连接池 Druid是什么? Druid是Alibaba开源的的数据库连接池.Druid能够提供强大的监控和扩展功能. 在哪里下载druid maven中央仓库: ...
- 【SpringBoot | Druid】SpringBoot整合Druid
SpringBoot整合Druid Druid是个十分强大的后端管理工具,具体的功能和用途请问阿里爸爸 1. 在pom.xml中导入包 <!-- alibaba 的druid数据库连接池 --& ...
- springboot整合druid、mybatis
目的: 1.springboot配置数据库连接池druid 测试druid中url监控 2.springboot整合mybatis 测试查删案例 3.springboot整合pagehelper sp ...
- springboot整合druid和配置资源监控
1.添加依赖,在maven repository中搜索 <dependency> <groupId>com.alibaba</groupId> <artifa ...
- springboot整合druid连接池、mybatis实现多数据源动态切换
demo环境: JDK 1.8 ,Spring boot 1.5.14 一 整合durid 1.添加druid连接池maven依赖 <dependency> <groupId> ...
- 【SpringBoot笔记】SpringBoot整合Druid数据连接池
废话少说,按SpringBoot的老套路来. [step1]:添加依赖 <!-- 数据库连接池 --> <dependency> <groupId>com.alib ...
- SpringBoot整合Druid数据源
关于SpringBoot数据源请参考我上一篇文章:https://www.cnblogs.com/yueshutong/p/9409295.html 一:Druid介绍 1. Druid是什么? Dr ...
- SpringBoot整合Druid(阿里巴巴)数据源
(1).添加相关依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId ...
- springboot整合druid数据库连接池并开启监控
简介 Druid是一个关系型数据库连接池,它是阿里巴巴的一个开源项目.Druid支持所有JDBC兼容的数据库,包括Oracle.MySQL.Derby.PostgreSQL.SQL Server.H2 ...
随机推荐
- 7 种 join
DROP TABLE IF EXISTS `test_student`; CREATE TABLE `test_student` ( `id` ) NOT NULL COMMENT '学号', `se ...
- vim 常用 NERDTree 快捷键
ctrl + w + h 光标 focus 左侧树形目录 ctrl + w + l 光标 focus 右侧文件显示窗口 ctrl + w + w 光标自动在左右侧窗口切换 ctrl + w + r 移 ...
- Linux----------httpd的简介和安装及使用
目录 一.httpd的简介 二.常用httpd版本特性 (1)httpd-2.2 (2)httpd-2.4 三.httpd的工作模型 四.httpd的程序环境即配置文件和重要目录 1.配置文件和重要目 ...
- 思科模拟器-使用vlan划分子网
此博客为初始化版本,未经完善,后续我再整理一下 小技巧:有时候我们不小心执行了一条错误命令,可以尝试使用在该命令前加一个no进行撤销 首先说一下网络设备的选择 在该实验中我主要用到一台三层交换机(思科 ...
- zabbix监测图形界面显示方框乱码解决方法
思路如下:用Windows下中文字体进行替换,修改配置文件即可 详细步骤如下: 1.在Windows的控制面板里的字体中,选择一种中文字体,将该字体文件复制到桌面.例如,我选择了宋体 常规字体,复制到 ...
- java-同一用户顶替操作(session过期或无效)
同一账号后者登录前者被强制退出:(可以通过监听器或过滤器进行监测session是否无效) 首先根据输入的用户名和密码做验证,通过验证查询用户信息.在用户信息不为空的前提下,比较静态变量中的sessio ...
- Ubuntu安装ssh 与samba
1.安装ssh服务 sudo apt-get install openssh-server 2.开启ssh(/etc/init.d文件夹) sudo service ssh start 2.安装sam ...
- 写好的Java代码在命令窗口运行——总结
步骤: 1.快捷键 win+r,在窗口中输入cmd,enter键进入DOS窗口. 2.假设写好的代码的目录为:D:\ACM 在DOS中依次写入:cd d: cd ACM 利用cd切换到代码文件所在的目 ...
- Django-Form组件之字段
Form类 创建Form类时,主要涉及到 [字段] 和 [插件],字段用于对用户请求数据的验证,插件用于自动生成HTML; 1.Django内置字段如下: 1 2 3 4 5 6 7 8 9 10 1 ...
- 简单的AOP标签
常用标签 1.1<aop:config> //作用 用于声明aop的配置 //配置:<aop:config></aop:config> 1.2 <aop:as ...