https://www.cnblogs.com/gslblog/p/7169481.htmlhtml
在配置文件中添加配置以下(我使用的是多數據源):mysql
spring.datasource.primary.url=jdbc\:mysql\://localhost\:3306/test?useUnicode\=true&characterEncoding\=utf-8
spring.datasource.primary.username=test
spring.datasource.primary.password=123456
spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver
#驗證鏈接的有效性
spring.datasource.primary.test-while-idle=true
#獲取鏈接時候驗證,會影響性能
spring.datasource.primary.test-on-borrow=false
#在鏈接歸還到鏈接池時是否測試該鏈接
spring.datasource.primary.test-on-return=false
spring.datasource.primary.validation-query=SELECT 1 FROM DUAL
#空閒鏈接回收的時間間隔,與test-while-idle一塊兒使用,設置5分鐘
spring.datasource.primary.time-between-eviction-runs-millis=300000
#鏈接池空閒鏈接的有效時間 ,設置30分鐘
spring.datasource.primary.min-evictable-idle-time-millis=1800000
spring.datasource.primary.initial-size=5
#指定鏈接池中最大的活躍鏈接數.
spring.datasource.primary.max-active=50
#指定鏈接池等待鏈接返回的最大等待時間,毫秒單位.
spring.datasource.primary.max-wait=60000
#指定必須保持鏈接的最小值
spring.datasource.primary.min-idle=5spring
spring.datasource.secondary.url=jdbc\:mysql\://localhost\:3306/test2?useUnicode\=true&characterEncoding\=utf-8
spring.datasource.secondary.username=test
spring.datasource.secondary.password=123456
spring.datasource.secondary.driver-class-name=com.mysql.jdbc.Driver
#驗證鏈接的有效性
spring.datasource.secondary.test-while-idle=true
#獲取鏈接時候驗證,會影響性能
spring.datasource.secondary.test-on-borrow=false
#在鏈接歸還到鏈接池時是否測試該鏈接
spring.datasource.secondary.test-on-return=false
spring.datasource.secondary.validation-query=SELECT 1 FROM DUAL
#空閒鏈接回收的時間間隔,與test-while-idle一塊兒使用,設置5分鐘
spring.datasource.secondary.time-between-eviction-runs-millis=300000
#鏈接池空閒鏈接的有效時間 ,設置30分鐘
spring.datasource.secondary.min-evictable-idle-time-millis=1800000
spring.datasource.secondary.initial-size=5
#指定鏈接池中最大的活躍鏈接數.
spring.datasource.secondary.max-active=50
#指定鏈接池等待鏈接返回的最大等待時間,毫秒單位.
spring.datasource.secondary.max-wait=60000
#指定必須保持鏈接的最小值
spring.datasource.secondary.min-idle=5sql
spring.dao.exceptiontranslation.enabled是否開啓PersistenceExceptionTranslationPostProcessor,默認爲true數據庫
spring.datasource.abandon-when-percentage-full設定超時被廢棄的鏈接佔到多少比例時要被關閉或上報性能
spring.datasource.allow-pool-suspension使用Hikari pool時,是否容許鏈接池暫停,默認爲: false測試
spring.datasource.alternate-username-allowed是否容許替代的用戶名.編碼
spring.datasource.auto-commit指定updates是否自動提交.url
spring.datasource.catalog指定默認的catalog.spa
spring.datasource.commit-on-return設置當鏈接被歸還時,是否要提交全部還未完成的事務
spring.datasource.connection-init-sql指定鏈接被建立,再被添加到鏈接池以前執行的sql.
spring.datasource.connection-init-sqls使用DBCP connection pool時,指定初始化時要執行的sql
spring.datasource.connection-properties.[key]在使用DBCP connection pool時指定要配置的屬性
spring.datasource.connection-test-query指定校驗鏈接合法性執行的sql語句
spring.datasource.connection-timeout指定鏈接的超時時間,毫秒單位.
spring.datasource.continue-on-error在初始化數據庫時,遇到錯誤是否繼續,默認false
spring.datasource.data指定Data (DML)腳本
spring.datasource.data-source-class-name指定數據源的全限定名.
spring.datasource.data-source-jndi指定jndi的地址
spring.datasource.data-source-properties.[key]使用Hikari connection pool時,指定要設置的屬性
spring.datasource.db-properties使用Tomcat connection pool,指定要設置的屬性
spring.datasource.default-auto-commit是否自動提交.
spring.datasource.default-catalog指定鏈接默認的catalog.
spring.datasource.default-read-only是否設置默認鏈接只讀.
spring.datasource.default-transaction-isolation指定鏈接的事務的默認隔離級別.
spring.datasource.driver-class-name指定driver的類名,默認從jdbc url中自動探測.
spring.datasource.fair-queue是否採用FIFO返回鏈接.
spring.datasource.health-check-properties.[key]使用Hikari connection pool時,在心跳檢查時傳遞的屬性
spring.datasource.idle-timeout指定鏈接多久沒被使用時,被設置爲空閒,默認爲10ms
spring.datasource.ignore-exception-on-pre-load當初始化鏈接池時,是否忽略異常.
spring.datasource.init-sql當鏈接建立時,執行的sql
spring.datasource.initial-size指定啓動鏈接池時,初始創建的鏈接數量
spring.datasource.initialization-fail-fast當建立鏈接池時,無法建立指定最小鏈接數量是否拋異常
spring.datasource.initialize指定初始化數據源,是否用data.sql來初始化,默認: true
spring.datasource.isolate-internal-queries指定內部查詢是否要被隔離,默認爲false
spring.datasource.jdbc-interceptors使用Tomcat connection pool時,指定jdbc攔截器,分號分隔
spring.datasource.jdbc-url指定JDBC URL.
spring.datasource.jmx-enabled是否開啓JMX,默認爲: false
spring.datasource.jndi-name指定jndi的名稱.
spring.datasource.leak-detection-threshold使用Hikari connection pool時,多少毫秒檢測一次鏈接泄露.
spring.datasource.log-abandoned使用DBCP connection pool,是否追蹤廢棄statement或鏈接,默認爲: false
spring.datasource.log-validation-errors當使用Tomcat connection pool是否打印校驗錯誤.
spring.datasource.login-timeout指定鏈接數據庫的超時時間.
spring.datasource.max-active指定鏈接池中最大的活躍鏈接數.
spring.datasource.max-age指定鏈接池中鏈接的最大年齡
spring.datasource.max-idle指定鏈接池最大的空閒鏈接數量.
spring.datasource.max-lifetime指定鏈接池中鏈接的最大生存時間,毫秒單位.
spring.datasource.max-open-prepared-statements指定最大的打開的prepared statements數量.
spring.datasource.max-wait指定鏈接池等待鏈接返回的最大等待時間,毫秒單位.
spring.datasource.maximum-pool-size指定鏈接池最大的鏈接數,包括使用中的和空閒的鏈接.
spring.datasource.min-evictable-idle-time-millis指定一個空閒鏈接最少空閒多久後可被清除.
spring.datasource.min-idle指定必須保持鏈接的最小值(For DBCP and Tomcat connection pools)
spring.datasource.minimum-idle指定鏈接維護的最小空閒鏈接數,當使用HikariCP時指定.
spring.datasource.name指定數據源名.
spring.datasource.num-tests-per-eviction-run指定運行每一個idle object evictor線程時的對象數量
spring.datasource.password指定數據庫密碼.
spring.datasource.platform指定schema要使用的Platform(schema-${platform}.sql),默認爲: all
spring.datasource.pool-name指定鏈接池名字.
spring.datasource.pool-prepared-statements指定是否池化statements.
spring.datasource.propagate-interrupt-state在等待鏈接時,若是線程被中斷,是否傳播中斷狀態.
spring.datasource.read-only當使用Hikari connection pool時,是否標記數據源只讀
spring.datasource.register-mbeans指定Hikari connection pool是否註冊JMX MBeans.
spring.datasource.remove-abandoned指定當鏈接超過廢棄超時時間時,是否馬上刪除該鏈接.
spring.datasource.remove-abandoned-timeout指定鏈接應該被廢棄的時間.
spring.datasource.rollback-on-return在歸還鏈接時,是否回滾等待中的事務.
spring.datasource.schema指定Schema (DDL)腳本.
spring.datasource.separator指定初始化腳本的語句分隔符,默認: ;
spring.datasource.sql-script-encoding指定SQL scripts編碼.
spring.datasource.suspect-timeout指定打印廢棄鏈接前的超時時間.
spring.datasource.test-on-borrow當從鏈接池借用鏈接時,是否測試該鏈接.
spring.datasource.test-on-connect建立時,是否測試鏈接
spring.datasource.test-on-return在鏈接歸還到鏈接池時是否測試該鏈接.
spring.datasource.test-while-idle當鏈接空閒時,是否執行鏈接測試.
spring.datasource.time-between-eviction-runs-millis指定空閒鏈接檢查、廢棄鏈接清理、空閒鏈接池大小調整之間的操做時間間隔
spring.datasource.transaction-isolation指定事務隔離級別,使用Hikari connection pool時指定
spring.datasource.url指定JDBC URL.
spring.datasource.use-disposable-connection-facade是否對鏈接進行包裝,防止鏈接關閉以後被使用.
spring.datasource.use-equals比較方法名時是否使用String.equals()替換==.
spring.datasource.use-lock是否對鏈接操做加鎖
spring.datasource.username指定數據庫名.
spring.datasource.validation-interval指定多少ms執行一次鏈接校驗.
spring.datasource.validation-query指定獲取鏈接時鏈接校驗的sql查詢語句.
spring.datasource.validation-query-timeout指定鏈接校驗查詢的超時時間.
spring.datasource.validation-timeout設定鏈接校驗的超時時間,當使用Hikari connection pool時指定
spring.datasource.validator-class-name用來測試查詢的validator全限定名.
spring.datasource.xa.data-source-class-name指定數據源的全限定名.
spring.datasource.xa.properties指定傳遞給XA data source的屬性