SpringBoot2配置Druid數據源及監控

<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&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的錯誤html

監測頁面:http://localhost:端口/druid/index.htmlmysql

參考:web

http://www.javashuo.com/article/p-uooanujc-hn.htmlspring

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

相關文章
相關標籤/搜索