SpringBoot2配置Druid数据源及监控丶一个站在Java后端设计之路的男青年个人博客网站

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>            
</dependency>

application.yml配置

# 项目配置
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&amp;useSSL=false&amp;characterEncoding=UTF-8&amp;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的错误

监测页面:http://localhost:端口/druid/index.html

参考:

https://blog.csdn.net/qq_38455201/article/details/80769354

https://www.cnblogs.com/sunny3096/p/9884648.html


Original url: Access
Created at: 2020-04-10 16:29:25
Category: default
Tags: none

请先后发表评论
  • 最新评论
  • 总共0条评论