栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringBoot整合Druid数据库连接池的方法

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringBoot整合Druid数据库连接池的方法

一,Druid是什么?

Druid是Java语言中最好的数据库连接池。Druid能够提供强大的监控和扩展功能。

二, 在哪里下载druid

maven中央仓库: http://central.maven.org/maven2/com/alibaba/druid/

三, 怎么获取Druid的源码

Druid是一个开源项目,源码托管在github上,源代码仓库地址是 https://github.com/alibaba/druid。同时每次Druid发布正式版本和快照的时候,都会把源码打包,你可以从上面的下载地址中找到相关版本的源码

SpringBoot整合Druid数据库连接池的方法。

项目配置

pom.xml

 
   com.alibaba
   druid
   1.1.10
  
  
  
   com.alibaba
   druid-spring-boot-starter
   1.1.10
  

application.yml

server:
 port: 8080

spring:
 datasource:
 username: root
 password: root
 url: jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
 driver-class-name: com.mysql.cj.jdbc.Driver

 type: com.alibaba.druid.pool.DruidDataSource
 initialSize: 5
 minIdle: 5
 maxActive: 20
 maxWait: 60000
 timeBetweenEvictionRunsMillis: 60000
 minEvictableIdleTimeMillis: 300000
 validationQuery: SELECt 1 FROM DUAL
 testWhileIdle: true
 testOnBorrow: false
 testOnReturn: false
 poolPreparedStatements: true
 maxPoolPreparedStatementPerConnectionSize: 25
 filters: stat,wall,slf4j
 connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
 useGlobalDataSourceStat: true

 cache:
 type: redis
 redis:
 host: 127.0.0.1
 port: 6379
 password:
 pool:
  max-active: 100
  max-idle: 10
  max-wait: 100000
 lettuce:
  shutdown-timeout: 0
 timeout: 5000
 database: 0

thymeleaf:
 cache: false;

mybatis:
 mapper-locations: classpath:zhw.example.zhw.loginModule.loginDao
 @Bean
 public ServletRegistrationBean servletRegistrationBean() {
  ServletRegistrationBean bean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid
 @Bean
 public FilterRegistrationBean filterRegistrationBean() {
  FilterRegistrationBean bean = new FilterRegistrationBean<>();
  bean.setFilter(new WebStatFilter());
  Map map = new HashMap<>();
  //移除这些监听
  map.put(WebStatFilter.PARAM_NAME_EXCLUSIONS, "*.js,*.css,/druid/*,*.gif,*.jpg,*.png");
  bean.setInitParameters(map);
  //拦截所有请求,全部都要走druid监听
  bean.setUrlPatterns(Collections.singletonList("/*"));
  return bean;
 }

}

测试配置url白名单

如果工程中配置了Apache Shiro,需要在配置类中添加白名单

监控界面

到此这篇关于SpringBoot整合Druid数据库连接池的方法的文章就介绍到这了,更多相关SpringBoot整合Druid数据库连接池内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/133236.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号