当前位置: 首页 > news >正文

SpringBoot整合Druid配置yml文件

springboot中引入依赖注意,否则yml中配置不生效

<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.1</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.19</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.0.33</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies>

yml配置文件填写

spring:datasource:# 连接池类型 type: com.alibaba.druid.pool.DruidDataSource# Druid的其他属性配置 springboot3整合情况下,数据库连接信息必须在Druid属性下!druid:url: jdbc:mysql://localhost:3306/testusername: rootpassword: 123456driver-class-name: com.mysql.cj.jdbc.Driver# 初始化时建立物理连接的个数initial-size: 5# 连接池的最小空闲数量min-idle: 5# 连接池最大连接数量max-active: 20# 获取连接时最大等待时间,单位毫秒max-wait: 60000# 申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。test-while-idle: true# 既作为检测的间隔时间又作为testWhileIdel执行的依据time-between-eviction-runs-millis: 60000# 销毁线程时检测当前连接的最后活动时间和当前时间差大于该值时,关闭当前连接(配置连接在池中的最小生存时间)min-evictable-idle-time-millis: 30000# 用来检测数据库连接是否有效的sql 必须是一个查询语句(oracle中为 select 1 from dual)validation-query: select 1# 申请连接时会执行validationQuery检测连接是否有效,开启会降低性能,默认为truetest-on-borrow: false# 归还连接时会执行validationQuery检测连接是否有效,开启会降低性能,默认为truetest-on-return: false# 是否缓存preparedStatement, 也就是PSCache,PSCache对支持游标的数据库性能提升巨大,比如说oracle,在mysql下建议关闭。pool-prepared-statements: false# 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100max-pool-prepared-statement-per-connection-size: -1# 合并多个DruidDataSource的监控数据use-global-data-source-stat: truelogging:level:root: debug

http://www.lryc.cn/news/187045.html

相关文章:

  • 如何保证 RabbitMQ 的消息可靠性?
  • 图像分类数据集划分(创建ImageNet格式的数据集)
  • ArcGIS Engine:报错无法嵌入互操作类型“ESRI.ArcGIS.Geometry.EnvelopeClass”。请改用适用的接口。
  • 核货宝:服装店收银系统如何选择?收银系统选购指南!
  • GB/T 7134-2008 浇筑型工业有机玻璃板材检测
  • 数据采集平台(二)
  • Nginx + PHP 异常排查,open_basedir 异常处理
  • Linux免密登录
  • 迷宫 蓝桥杯
  • 25 mysql like 是否使用索引
  • Android---Class 对象在执行引擎中的初始化过程
  • Altium Designer实用系列(二)----PCB绘图小技巧
  • threejs-开发入门与调试设置
  • win11安装双系统Ubuntu的坎坷记录
  • 关于docker的xuexi
  • Python接口自动化测试实战详解,你想要的全都有
  • SparkSQL 外部数据源
  • leetcode做题笔记167. 两数之和 II - 输入有序数组
  • [ZJCTF 2019]NiZhuanSiWei - 伪协议+文件包含+反序列化
  • 如何提升和扩展 PostgreSQL — 从共享缓冲区到内存数据网格
  • Elasticsearch:使用 huggingface 模型的 NLP 文本搜索
  • 论文解析——异构多芯粒神经网络加速器
  • MyBatisPlus(十六)逻辑删除
  • 基于黏菌优化的BP神经网络(分类应用) - 附代码
  • C语言基础语法复习08-位域bit-fields
  • 3.2.OpenCV技能树--二值图像处理--图像腐蚀与膨胀
  • 基于FPGA的数字时钟系统设计
  • linux centos Python + Selenium+Chrome自动化测试环境搭建?
  • mysql面试题20:有哪些合适的分布式主键方案
  • git的基础操作