1. 程式人生 > >SpringBoot中配置使用Druid資料庫連線池

SpringBoot中配置使用Druid資料庫連線池

Druid 是阿里巴巴開源的Java資料庫連線池外掛,Druid能夠提供強大的監控和擴充套件功能

配置使用Druid資料庫連線池

新增依賴

  • Gradle
compile('com.alibaba:druid-spring-boot-starter:${version}')
  • Maven
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>${version}</version>

配置資料庫連線

  • JDBC 配置
spring.datasource.druid.url= # 或spring.datasource.url= 
spring.datasource.druid.username= # 或spring.datasource.username=
spring.datasource.druid.password= # 或spring.datasource.password=
spring.datasource.druid.driver-class-name= #或 spring.datasource.driver-class-name=
  • 連線池配置
spring.datasource
.druid.initial-size= spring.datasource.druid.max-active= spring.datasource.druid.min-idle= spring.datasource.druid.max-wait= spring.datasource.druid.pool-prepared-statements= spring.datasource.druid.max-pool-prepared-statement-per-connection-size= spring.datasource.druid.max-open-prepared-statements= #和上面的等價
spring.datasource.druid.validation-query= spring.datasource.druid.validation-query-timeout= spring.datasource.druid.test-on-borrow= spring.datasource.druid.test-on-return= spring.datasource.druid.test-while-idle= spring.datasource.druid.time-between-eviction-runs-millis= spring.datasource.druid.min-evictable-idle-time-millis= spring.datasource.druid.max-evictable-idle-time-millis= spring.datasource.druid.filters= #配置多個英文逗號分隔 ....//more
  • 監控配置
# WebStatFilter配置,說明請參考Druid Wiki,配置_配置WebStatFilter
spring.datasource.druid.web-stat-filter.enabled= #是否啟用StatFilter預設值true
spring.datasource.druid.web-stat-filter.url-pattern=
spring.datasource.druid.web-stat-filter.exclusions=
spring.datasource.druid.web-stat-filter.session-stat-enable=
spring.datasource.druid.web-stat-filter.session-stat-max-count=
spring.datasource.druid.web-stat-filter.principal-session-name=
spring.datasource.druid.web-stat-filter.principal-cookie-name=
spring.datasource.druid.web-stat-filter.profile-enable=

# StatViewServlet配置,說明請參考Druid Wiki,配置_StatViewServlet配置
spring.datasource.druid.stat-view-servlet.enabled= #是否啟用StatViewServlet預設值true
spring.datasource.druid.stat-view-servlet.url-pattern=
spring.datasource.druid.stat-view-servlet.reset-enable=
spring.datasource.druid.stat-view-servlet.login-username=
spring.datasource.druid.stat-view-servlet.login-password=
spring.datasource.druid.stat-view-servlet.allow=
spring.datasource.druid.stat-view-servlet.deny=

# Spring監控配置,說明請參考Druid Github Wiki,配置_Druid和Spring關聯監控配置
spring.datasource.druid.aop-patterns= # Spring監控AOP切入點,如x.y.z.service.*,配置多個英文逗號分隔
# 如果spring.datasource.druid.aop-patterns要代理的類沒有定義interface請設定spring.aop.proxy-target-class=true

參考模板

spring.datasource.druid.url=jdbc:mysql://localhost:3306/db?useSSL=false
spring.datasource.druid.slave.username=root
spring.datasource.druid.slave.password=123456

# Druid dataSource config
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.druid.initial-size=5
spring.datasource.druid.max-active=20
spring.datasource.druid.min-idle=5
spring.datasource.druid.max-wait=60000
spring.datasource.druid.pool-prepared-statements=true
spring.datasource.druid.max-pool-prepared-statement-per-connection-size=20
spring.datasource.druid.max-open-prepared-statements=20
spring.datasource.druid.validation-query=SELECT 1
spring.datasource.druid.validation-query-timeout=30000
spring.datasource.druid.test-on-borrow=true
spring.datasource.druid.test-on-return=false
spring.datasource.druid.test-while-idle=false
#spring.datasource.druid.time-between-eviction-runs-millis=
#spring.datasource.druid.min-evictable-idle-time-millis=
#spring.datasource.druid.max-evictable-idle-time-millis=10000

# Druid stat filter config
spring.datasource.druid.filters=stat,wall,log4j
spring.datasource.druid.web-stat-filter.enabled=true 
spring.datasource.druid.web-stat-filter.url-pattern=/druid/*
#spring.datasource.druid.web-stat-filter.exclusions=
spring.datasource.druid.web-stat-filter.session-stat-enable=true
spring.datasource.druid.web-stat-filter.session-stat-max-count=10
#spring.datasource.druid.web-stat-filter.principal-session-name=
#spring.datasource.druid.web-stat-filter.principal-cookie-name=
spring.datasource.druid.web-stat-filter.profile-enable=true
spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*
spring.datasource.druid.filter.stat.db-type=mysql
spring.datasource.druid.filter.stat.log-slow-sql=true
spring.datasource.druid.filter.stat.slow-sql-millis=1000
spring.datasource.druid.filter.stat.merge-sql=true
spring.datasource.druid.filter.wall.enabled=true
spring.datasource.druid.filter.wall.db-type=mysql
spring.datasource.druid.filter.wall.config.delete-allow=true
spring.datasource.druid.filter.wall.config.drop-table-allow=false

# Druid manage page config
spring.datasource.druid.stat-view-servlet.enabled=true
spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*
spring.datasource.druid.stat-view-servlet.reset-enable=true
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.druid.stat-view-servlet.login-password=admin
#spring.datasource.druid.stat-view-servlet.allow=
#spring.datasource.druid.stat-view-servlet.deny=

相關推薦

springboot 整合阿里 Druid 資料庫連線

一,Druid是什麼? Druid是Java語言中最好的資料庫連線池。Druid能夠提供強大的監控和擴充套件功能。 二, 在哪裡下載druid 三, 怎麼獲取Druid的原始碼 Druid是一個開源專案,原始碼託管在github上,原始碼倉庫

在tomcat下context.xml配置各種資料庫連線

Tomcat6的伺服器配置檔案放在 ${tomcat6}/conf 目錄底下。我們可以在這裡找到 server.xml 和 context.xml。當然,還有其他一些資原始檔。但是在在本文中我們只用得上這兩個,其他的就不介紹了。 1. 首先,需要為資料來源配置一個JN

jfinal下配置druid資料庫連線

</pre></div><div><span style="font-size:18px"></span><pre name="code" class="java">public void configPlugin(Plugins plu

SpringBoot配置使用Druid資料庫連線

Druid 是阿里巴巴開源的Java資料庫連線池外掛,Druid能夠提供強大的監控和擴充套件功能 配置使用Druid資料庫連線池 新增依賴 Gradle compile('com.alibaba:druid-spring-boot-sta

springboot配置預設資料庫連線並解決初始連線未生效問題

目前Spring Boot中預設支援的連線池有dbcp,dbcp2, tomcat, hikari三種連線池。  在springboot1.5之前預設tomcat連線池, 版本org.springframework.boot.autoconfigure.jdbc.Data

druid 資料庫連線的詳細配置

首先說一下自己程式中遇到的問題,前一段時間新寫了一個專案,主要架構改進,為前端提供介面(spring +springmvc+mybatis) 在新專案中使用的是阿里的druid連線池,配置簡單,除了資料庫地址,驅動類,使用者名稱和密碼其他一起都是預設,開始的時候由於專案更新上線頻率比較多,沒有出現太

SpringBoot初始教程之資料庫連線(druid)

SpringBoot初始教程之資料庫連線池(druid) 1.介紹 Druid是一個JDBC元件庫,包括資料庫連線池、SQL Parser等元件。DruidDataSource是最好的資料庫連線池。SpringBoot支援任何一種資料庫連結池的配置,在這裡用druid作為例子進行講解 2

阿里Druid資料庫連線配置解釋

#阿里資料庫連線池Druid配置 # 初始化連線大小 spring.datasource.druid.initial-size=20 # 最小空閒連線數 spring.datasource.druid.minIdle=20 # 最大連線數 spring.datasource.druid.maxAct

SpringBoot使用MongoDB的連線配置

在SpringBoot中,我們可以通過引入 spring-boot-starter-data-mongodb 依賴來實現spring-data-mongodb 的自動配置。但是,預設情況下,該依賴並沒有像使用MySQL或者Redis那樣為我們提供連線池配置的功能。因此,我們需要自行重寫 Mong

基於Druid資料庫連線的資料來源配置資料庫連線密碼加密解密

Druid的資料庫連線池配置。 <!-- 基於Druid資料庫連線池的資料來源配置 --> <bean id="dataSource" class="com.alibaba.drui

Spring Boot 整合 Mybatis(druid 資料庫連線 以及 分頁配置

MyBatis 是一款優秀的持久層框架,它支援定製化 SQL、儲存過程以及高階對映,目前很大一部分網際網路、軟體公司都在使用這套框架 下來來之後,我們主要關注幾個檔案 配置檔案:generator.properties 主要是資料庫的相關配置,以及檔案生成的根路徑 generator.jdbc.drive

Springboot+druid資料庫連線使用

1. 為什麼要使用資料庫連線池        使用資料庫連線池主要考慮到程式與資料庫建立連線的效能。建立一個新的資料庫是一個很耗時的過程,在使用完之後,可能還需要不斷的釋放建立的連線,對資源的損耗大。        而採用資料庫連線池之後,首先就建立了固定數量的資料庫連線,需

阿里DRUID資料庫連線配置

DRUID介紹     Druid是阿里實現的一個開源資料庫連線池,在功能、效能、擴充套件性方面,都超過其他資料庫連線池,包括DBCP、C3P0、BoneCP、Proxool、JBoss DataSource。同時Druid還提供了封裝的sql監控,u

springmvc(五)整合阿里 druid資料庫連線和事務等配置,整合mybatis

感謝我們的小領導,他在研究,我們在套用,他走了以後再沒有完善過,一直沿用至今。如果看這裡的朋友有什麼需要整合進來的,不吝賜教,謝謝各位了。 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http:

jfinal druid資料庫連線配置

在jfinal配置類的configPlugin(Plugins me)中配置外掛 /** * 配置外掛<br> * 1,druid資料庫連線池<br> * 2,配置ActiveRecord外掛<br>

springBoot(八)整合之整合阿里druid資料庫連線

         當時是基於C3P0處理資料庫,然後偶發性出現連線超時,然後加上需要檢視連線次數以及訪問次數,我就想到採用druid資料庫連線池,話不多說,先上程式碼 其實下面的部分出於演示,用硬編碼,其實完全可以通過配置屬性,來進行動態改變,至於SpringCloud

javalite 使用druid資料庫連線配置

在pom檔案中引入jar包 <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId>

SpringBoot 配置 Druid

AS not 方法 view http web DC class import 這裏只舉了一個例子,其他按照官方文檔進行修改,使用 registration.addInitParameter 這個方法。 import com.alibaba.druid.support.ht

測試druid資料庫連線併發遇到的問題

測試條件配置: 1:配置druid連線池最大數量為500(maxActive=500)。 2:測試併發量為1000。 報錯:Data source rejected establishment of connection,  message from server: "Too

Druid資料庫連線問題,ERROR c.alibaba.druid.poo l.DruidDataSource

14:07:41.550 [Druid-ConnectionPool-Destroy-1326667259] ERROR c.alibaba.druid.poo l.DruidDataSource - abandon connection, owner thread: loc