pom
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
yml
druid:
initial-size: 5
min-idle: 1
max-active: 20
query-timeout: 6000
#設置removeAbandoned="true"時,當連接池連接數到達(getNumIdle() < 2) and (getNumActive() > getMaxActive() - 3) [空閒的連接小於2並且活動的連接大於(最大連接-3)] 時便會啓動連接回收,
#那種活動時間超過removeAbandonedTimeout="1800"的連接將會被回收,
#同時如果logAbandoned="true"設置爲true,程序在回收連接的同時會打印日誌。
#removeAbandoned是連接池的高級功能,理論上這中配置不應該出現在實際的生產環境,因爲有時應用程序執行長事務,可能這種情況下,會被連接池誤回收,該種配置一般在程序測試階段,爲了定位連接泄漏的具體代碼位置,被開啓。
#生產環境中連接的關閉應該靠程序自己保證。
#先關着
remove-abandoned: false
#必須要remove-abandoned爲false才能生效,這樣連接出問題的時候,每隔3000秒請求
async-init: true
time-between-connect-error-millis: 3000
#先關着
log-abandoned: false
transaction-query-timeout: 6000
remove-abandoned-timeout: 1800
filters: wall,stat
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=10000
stat-view-servlet:
login-username: bda
login-password: bda
url-pattern: /druid/*
reset-enable: false
web-stat-filter:
url-pattern: /*
exclusions: "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"
#超時重試次數
connection-error-retry-attempts: 3
#必須爲false(失敗後會不斷請求數據庫,請求在TIME-WAIT,在數據庫服務重啓後,所有等待請求會訪問數據庫),
#爲true上面參數纔會生效(:true表示pool向數據庫上面的重試請求連接此時失敗後標記整個pool爲block並close,
#就算後端數據庫恢復正常也不進行重連,客戶端對pool的請求都拒絕掉。false表示不會標記 pool爲block,新的請求都會嘗試去數據庫請求connection。
#默認爲false。因此,如果想讓數據庫和網絡故障恢復之後,pool能繼續請求正常資源必須把此項配置設爲false)
break-after-acquire-failure: false
#檢查連接正常的sql
validation-query: select 1 from dual
#配置多久檢測一次空閒連接(可以選擇是否儘早關閉連接,看壓力在server還是數據庫端)
time-between-eviction-runs-millis: 60000
#數據庫連接最小生存時間
min-evictable-idle-time-millis: 300000