springboot整合druid时,引入了druid的数据源,在配置文件application.yml中配置了相关配置
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://192.168.2.218:3306/test
driver-class-name: com.mysql.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
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,log4j
maxPoolPreparedStatementPerConnectionSize: 20
useGlobalDataSourceStat: true
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
schema:
- classpath:department.sql
但是在启动时报错:
根据报错提示:查看配置文件,该行代码是 filters: stat,wall,log4j
看报错原因Reason: org.apache.log4j.Logger,于是猜想少了log4j的相关依赖,在pom中引入相关依赖
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
再次启动,成功!