當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
SpringBoot 使用【p6spy-spring-boot-starter】集成 p6spy 监控数据库(配置方法举例)
生活随笔
收集整理的這篇文章主要介紹了
SpringBoot 使用【p6spy-spring-boot-starter】集成 p6spy 监控数据库(配置方法举例)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.簡單說明
p6spy 類似于 druid 可以攔截 SQL 可以用于項目調試,直接引入 p6spy 的博文已經很多了,這里主要是介紹一下 springboot 使用 p6spy-spring-boot-starter 如何進行配置。
2.核心依賴
<dependency><groupId>com.github.gavlyukovskiy</groupId><artifactId>p6spy-spring-boot-starter</artifactId><version>1.7.1</version> </dependency>3.主要配置
主要是【spring.datasource.driver-class-name】和【decorator.datasource.p6spy】相關配置。
spring:datasource:url: jdbc:p6spy:postgresql://xxx.xx.xxx.xxx:2345/gpdbusername: gpadminpassword: gpadmindriver-class-name: com.p6spy.engine.spy.P6SpyDrivertype: com.alibaba.druid.pool.DruidDataSource decorator:datasource:p6spy:logging: filelog-file: spy.loglog-format: executionTime:%(executionTime) | sql:%(sqlSingleLine)4.簡單測試
調用項目中的某個接口之后…可以看到在當前項目的文件夾下生成了 spy.log 文件,且輸出的格式跟 log-format 配置的是一致的。
executionTime:43 | sql:SELECT * FROM yz_test_match ytm WHERE ytm.field = '豫A666666';5.其他配置
logging: file 模式可以保存所有執行的SQL信息,在我們調試項目的時候,如果我們只需要控制臺打印,那么配置如下:
decorator:datasource:p6spy:logging: slf4j輸出結果如下:
2021-07-19 15:00:56.523 INFO 2948 --- [nio-8088-exec-6] p6spy : executionTime:42 | sql:SELECT * FROM yz_test_match ytm WHERE ytm.field = '豫A666666';總結
以上是生活随笔為你收集整理的SpringBoot 使用【p6spy-spring-boot-starter】集成 p6spy 监控数据库(配置方法举例)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【代码托管】如何使用Git工具托管本地代
- 下一篇: Hasor【付诸实践 02】Spring