spring Boot 自带的数据源连接有org.apache.tomcat.jdbc.pool.DataSource、HikariDataSource、BasicDataSource,但大部分项目中都是采用阿里druid,它包含一系列的监控组件,比较成熟,性能也不差。讲一下整合步骤
第一步:配置application.yml
spring:
datasource:
# 数据源基本配置
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/mytest
type: com.alibaba.druid.pool.DruidDataSource
schema:
- classpath:sql/department.sql
- classpath:sql/employee.sql
# 数据源其他配置
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
maxPoolPreparedStatementPe