一.pom(spring boot依赖省略)
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.3</version> </dependency> <!-- https://mvnrepository.com/artifact/p6spy/p6spy --> <dependency> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>3.8.7</version> </dependency> <dependency> <groupId>com.zaxxer</groupId> <artifactId>HikariCP</artifactId> <exclusions> <exclusion> <artifactId>slf4j-api</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency>
二.spring boot核心配置文件 application.properties
这里密码已经加密过
#--------------------------数据库连接配置--------------------------# spring.datasource.url=jdbc:p6spy:oracle:thin:@localhost:1521:orcl spring.datasource.username=OSS(YnJkgyX9hKL9YP76Ck5n8IFCVH3X7J2rbxRwJzblruQ=) spring.datasource.password=OSS(q3fNY6Rp6W5+QWIYvWTYSzEbKqmIkyi1LYBstYk0JHw=) spring.datasource.driver-class-name=com.p6spy.engine.spy.P6SpyDriver #------------------------hikari相关配置----------------------------# #数据源配置 spring.datasource.type=com.zaxxer.hikari.HikariDataSource #连接池名称,默认HikariPool-1 spring.datasource.hikari.pool-name=OssHikariPool #最大连接数,小于等于0会被重置为默认值10;大于零小于1会被重置为minimum-idle的值 spring.datasource.hikari.maximum-pool-size=12 #连接超时时间:毫秒 spring.datasource.hikari.connection-timeout=60000 #最小空闲连接 spring.datasource.hikari.minimum-idle=10 #空闲连接超时时间 # 只有空闲连接数大于最大连接数且空闲时间超过该时,才会被释放 spring.datasource.hikari.idle-timeout=500000 #连接最大存活时间 spring.datasource.hikari.max-lifetime=540000
三.p6spy核心配置文件spy.properties,直接放在resources目录下即可
# http://p6spy.readthedocs.io/en/latest/configandusage.html#common-property-file-settings #基本设置 autoflush=false dateformat=yyyy-MM-dd HH:mm:ss reloadproperties=false reloadpropertiesinterval=60 #定制输出 appender=com.p6spy.engine.spy.appender.Slf4JLogger logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat customLogMessageFormat=%(executionTime)ms | %(sqlSingleLine) #数据库日期 databaseDialectDateFormat=yyyy-MM-dd HH:mm:ss databaseDialectBooleanFormat=boolean # 使用p6spy driver来做代理 deregisterdrivers=true #实际驱动 driverlist=oracle.jdbc.OracleDriver #过滤不需要的SQL语句 filter=true exclude=Z020_LOG_RESOURCE,Z020_LOG_OPERATE #排除的语句类型 excludecategories=info,debug,result,resultset,commit,rollback
测试结果:
p6spy和hikari整合无误。