接下来我们需要在application.properties配置文件中配置Durid数据库连接池。本机需安装mysql数据库,一下配置为小编本机的数据库配置,数据库名为test,用户名为root,密码为123456。
spring.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.datasource.name=test#监控统计拦截的filtersspring.datasource.druid.filters=statspring.datasource.druid.driver-class-name=com.mysql.jdbc.Driverspring.datasource.druid.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf-8spring.datasource.druid.username=rootspring.datasource.druid.password=123456#配置连接池初始化大小、最小值、最大值spring.datasource.druid.initial-size=1spring.datasource.druid.min-idle=1spring.datasource.druid.max-active=20#获取连接等待超时时间spring.datasource.druid.max-wait=60000#间隔多久进行一次检测,检测需要关闭的空闲连接spring.datasource.druid.time-between-eviction-runs-millis=60000#一个连接在池中最小生存的时间spring.datasource.druid.min-evictable-idle-time-millis=300000spring.datasource.druid.validation-query=SELECT 1 FROM DUALspring.datasource.druid.test-while-idle= truespring.datasource.druid.test-on-borrow= falsespring.datasource.druid.test-on-return= false#打开PSCache,并指定每个连接上PSCache的大小spring.datasource.druid.pool-prepared-statements=falsespring.datasource.druid.max-pool-prepared-statement-per-connection-size=20# 通过connectProperties属性来打开mergeSql功能;慢SQL记录spring.datasource.druid.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000