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 ...
随机推荐
- 今天在2cto网站看到一个有关try{}catch(){}finally{}语句中含有return的讲解,理解很透彻。
publicclassTrycatchTest{ publicstaticvoidmain(String[]args){ System.out.println("x:"+newTr ...
- Cookie保存用户名和密码
首次登录: 第二次登录: 百度网盘: 链接: https://pan.baidu.com/s/12W4B5-Bfyc_021oyVYkEJw 提取码: r55h
- AGC002 F - Leftmost Ball
貌似哪里讲过这题..总之当时掉线了(理解能力又差水平又低选手的日常).. 看看题目,应该是DP. 尝试了几次换状态,毫无思路.那我们就来继续挖掘性质吧...为了更直观,我们令第i个出现的球颜色就是i( ...
- 6. Vulnerability scanners (漏洞扫描器 11个)
Nessus是最流行和最有能力的漏洞扫描程序之一,特别为UNIX系统. 它最初是免费的和开源的,但是他们在2005年关闭了源代码,并在2008年删除了免费的“注册Feed”版本.现在要每年花费2,19 ...
- win10 uwp 读取resw资源文件
ResourceContext resourceContext = ResourceContext.GetForViewIndependentUse(); ResourceMap resourceMa ...
- spring 普通类注入为null,通过自定义SpringUtils解决
package com.jathams.spring; import org.springframework.beans.BeansException; import org.springframew ...
- Day 18 常用模块(二)
一.随机数:RANDOM 1.(0,1)小数:random.random() 2.[1,10]整数:random.randint(1,10) 3.[1,10)整数:random.randrang(1, ...
- Idea debug时报错:Command line is too long
问题:写单元测试,debug时,报错 解决方法: 在项目/.idea/workspace.xml文件中添加一行代码如下 <component name="PropertiesCompo ...
- HashTable & HashMap & ConcurrentHashMap 原理与区别
一.三者的区别 HashTable HashMap ConcurrentHashMap 底层数据结构 数组+链表 数组+链表 数组+链表 key可为空 否 是 否 value可为空 否 是 否 ...
- 执行代码出现ImportError:attempted relative import with no known parent package
前言 在这篇文章中,我将会解析 ImportError: attempted relative import with no known parent package 这个异常的原因.当你在运行的py ...