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的更多相关文章

  1. SpringBoot整合Druid数据连接池

    SpringBoot整合Druid数据连接池 Druid是什么? Druid是Alibaba开源的的数据库连接池.Druid能够提供强大的监控和扩展功能. 在哪里下载druid maven中央仓库: ...

  2. 【SpringBoot | Druid】SpringBoot整合Druid

    SpringBoot整合Druid Druid是个十分强大的后端管理工具,具体的功能和用途请问阿里爸爸 1. 在pom.xml中导入包 <!-- alibaba 的druid数据库连接池 --& ...

  3. springboot整合druid、mybatis

    目的: 1.springboot配置数据库连接池druid 测试druid中url监控 2.springboot整合mybatis 测试查删案例 3.springboot整合pagehelper sp ...

  4. springboot整合druid和配置资源监控

    1.添加依赖,在maven repository中搜索 <dependency> <groupId>com.alibaba</groupId> <artifa ...

  5. springboot整合druid连接池、mybatis实现多数据源动态切换

    demo环境: JDK 1.8 ,Spring boot 1.5.14 一 整合durid 1.添加druid连接池maven依赖 <dependency> <groupId> ...

  6. 【SpringBoot笔记】SpringBoot整合Druid数据连接池

    废话少说,按SpringBoot的老套路来. [step1]:添加依赖 <!-- 数据库连接池 --> <dependency> <groupId>com.alib ...

  7. SpringBoot整合Druid数据源

    关于SpringBoot数据源请参考我上一篇文章:https://www.cnblogs.com/yueshutong/p/9409295.html 一:Druid介绍 1. Druid是什么? Dr ...

  8. SpringBoot整合Druid(阿里巴巴)数据源

    (1).添加相关依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId ...

  9. springboot整合druid数据库连接池并开启监控

    简介 Druid是一个关系型数据库连接池,它是阿里巴巴的一个开源项目.Druid支持所有JDBC兼容的数据库,包括Oracle.MySQL.Derby.PostgreSQL.SQL Server.H2 ...

随机推荐

  1. openpyxl工具总结

    1.openpyxl使用 涉及到单元格合并.赋值 ''' .格式转换 raw_data create_data boolean Bool uint8 UInt8 int8 Int8 uint16 UI ...

  2. 几何概型 uva11722

    #include<bits/stdc++.h> using namespace std; int t1,t2,s1,s2,w; int get(int b) { ; int d=s2-s1 ...

  3. XSS学习(二)

    尝试操作Cookie 创建一个cookie,需要提供cookie的名字,值,过期时间和相关路径等 <?php setcookie('user_id',123); ?> 它的作用是创建一个c ...

  4. 第五章HTML

    HTML介绍 标签:有一个头,一尾 <!DOCTYPE html><html lang="en"><head> <!-- 文档的标题.编码 ...

  5. 《python for data analysis》第四章,numpy的基本使用

    <利用python进行数据分析>第四章的程序,介绍了numpy的基本使用方法.(第三章为Ipython的基本使用) 科学计算.常用函数.数组处理.线性代数运算.随机模块…… # -*- c ...

  6. AE插件:能量激光描边光效特效Saber Mac汉化版

    与大家分享一款非常好用的AE插件Saber插件汉化版.videocopilot saber是一款能量激光描边光效特效AE插件,可以帮助用户制作出能量激光.传送门.霓虹灯.电流.光束.光剑等效果.小编现 ...

  7. jumpserver管理入门

    比较规范一点的步骤 1.先在用户管理查看用户组里,添加用户组 2.在用户管理查看用户里,添加用户 3.在资产管理里查看资产,添加资产.在批量增加那里可以使用表格快速导入添加 4.在授权管理里的系统用户 ...

  8. 左耳听风-ARTS-第4周(2019/4/21-2019/4/27)

    Algorithm 本周的算法题是删除已排序数据中的重复数字(https://leetcode.com/problems/remove-duplicates-from-sorted-array/).这 ...

  9. Django之 HelloWorld

    1.C:\Users\andy>django-admin startproject sundyblog   ## 创建项目     C:\Users\andy>cd sundyblog2. ...

  10. iOS Simulator 模拟器 与 Android Emulator 仿真器:为什么叫不同的英文名字?(待补充)

    iOS Simulator 模拟器 与 Android Emulator 仿真器:为什么叫不同的英文名字?(待补充)