<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency>
application.yml配置css
# 项目配置 spring: application: name: provider-user datasource: username: root password: driver-class-name: com.mysql.cj.jdbc.Driver # mysql8.0之前使用com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/enterprise?useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=GMT%2B8 #type: com.alibaba.druid.pool.DruidDataSource # 使用Druid数据源 druid: initial-size: 5 # 初始化大小 min-idle: 5 # 最小 max-active: 100 # 最大 max-wait: 60000 # 链接超时时间 time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测须要关闭的空闲链接,单位是毫秒 min-evictable-idle-time-millis: 300000 # 指定一个空闲链接最少空闲多久后可被清除,单位是毫秒 validationQuery: select 'x' test-while-idle: true # 当链接空闲时,是否执行链接测试 test-on-borrow: false # 当从链接池借用链接时,是否测试该链接 test-on-return: false # 在链接归还到链接池时是否测试该链接 filters: config,wall,stat # 配置监控统计拦截的filters,去掉后监控界面sql没法统计,'wall'用于防火墙 poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 maxOpenPreparedStatements: 20 connectionProperties: druid.stat.slowSqlMillis=200;druid.stat.logSlowSql=true;config.decrypt=true web-stat-filter: enabled: true url-pattern: /* exclusions: /druid/*,*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico session-stat-enable: true session-stat-max-count: 10 stat-view-servlet: enabled: true url-pattern: /druid/* reset-enable: true login-username: admin login-password: admin
注意:spring-boot2中不要使用配置中注掉的type属性,会报错String不能转换为DataSource的错误html
监测页面:http://localhost:端口/druid/index.htmlmysql
参考:web