阿里巴巴druid數(shù)據(jù)源springboot簡(jiǎn)單使用案例 Druid的內(nèi)置監(jiān)控頁(yè)面查看
很多程序員數(shù)據(jù)庫(kù)連接池的印象可有可無(wú),不使用連接池我們的程序也能正常運(yùn)行,可以無(wú)連接池這個(gè)概念,但是實(shí)際上現(xiàn)在的項(xiàng)目都會(huì)使用到阿里巴巴的Druid數(shù)據(jù)源.來(lái)看看那Druid入門(mén)使用.
1. 在pom文件引入starter
<!--druid數(shù)據(jù)源-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.18</version>
</dependency>
2. 編寫(xiě)配置文件
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1/springboot?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
username: root
password: root
type: com.alibaba.druid.pool.DruidDataSource
druid:
initialSize: 1
minIdle: 1
maxActive: 20
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: false
maxOpenPreparedStatements: 20
#開(kāi)啟StatFilter
filter:
stat:
enabled: true
log-slow-sql: true
slow-sql-millis: 1000
#開(kāi)啟Slf4jFilter
slf4j:
enabled: true
data-source-log-enabled: false
connection-log-enabled: false
statement-log-enabled: false
result-set-log-enabled: false
#開(kāi)啟WallFilter
wall:
enabled: true
log-violation: true
throw-exception: false
config:
delete-where-none-check: true
#開(kāi)啟Web監(jiān)控
web-stat-filter:
enabled: true
exclusions: /druid/*,*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico
url-pattern: /*
#開(kāi)啟監(jiān)控頁(yè)面
stat-view-servlet:
enabled: true
login-username: admin
login-password: z1320291471
3. 這里修改配置文件即刻,連接池就配置完成了 當(dāng)然這里配置的監(jiān)控頁(yè)面,可以輸入 127.0.0.1:8080/druid
,查看監(jiān)控頁(yè)面.登錄賬號(hào)密碼就是上方配置的賬號(hào)密碼login-username: admin
,login-password: z1320291471
整個(gè)頁(yè)面可以看到的東西還是蠻多.以下是部分截圖.
作者:思議歲月
鏈接:http://www.reibang.com/p/76e9c7f20a54
來(lái)源:簡(jiǎn)書(shū)
著作權(quán)歸作者所有陈症。商業(yè)轉(zhuǎn)載請(qǐng)聯(lián)系作者獲得授權(quán)应役,非商業(yè)轉(zhuǎn)載請(qǐng)注明出處罗标。