springboot 整合p6spy
时间: 2023-10-22 09:09:06 浏览: 196
要在Spring Boot中整合p6spy,需要在pom.xml中添加p6spy的依赖,并在application.properties中配置数据源以及p6spy的相关属性,例如:
pom.xml
```xml
<dependency>
<groupId>p6spy</groupId>
<artifactId>p6spy</artifactId>
<version>3.9.1</version>
</dependency>
```
application.properties
```properties
spring.datasource.driver-class-name=com.p6spy.engine.spy.P6SpyDriver
spring.datasource.url=jdbc:p6spy:mysql://localhost:3306/test_db
spring.datasource.username=root
spring.datasource.password=root
# p6spy配置
spy.properties=\
realdriver=com.mysql.cj.jdbc.Driver,\
useprefix=true,\
tracing=false,\
outagedetection=true,\
outagedetectioninterval=60,\
datasourceprovider=com.p6spy.engine.spy.P6DataSourceProvider,\
logfile=/logs/p6spy.log,\
appender=com.p6spy.engine.spy.appender.Slf4JLogger,\
logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat,\
customLogMessageFormat=[date] [executionTime] [category] [connectionId] [sql] [bindings]\n,\
include=com.example.test.*
```
其中,`logfile`表示p6spy日志文件的存放路径,`customLogMessageFormat`表示p6spy日志输出的格式,`include`表示需要被p6spy监控的数据源。
阅读全文