Springboot2 集成 druid 加密數(shù)據(jù)庫密碼的配置方法
一:環(huán)境
springboot 2.x
druid 1.1.21
二:druid加密數(shù)據(jù)庫密碼
本地下載druid-1.1.21.jar包,運行cmd,輸入命令
java -cp jar包路徑 com.alibaba.druid.filter.config.ConfigTools 數(shù)據(jù)庫密碼 java -cp druid-1.1.21.jar com.alibaba.druid.filter.config.ConfigTools 數(shù)據(jù)庫密碼
運行成功輸出
privateKey:MIIBVAIBAD...
publicKey:MFwwDQYJKo...
password:PNd/zcG+JEn...
將得到的publicKey、password分別填充進yml配置文件即可
三:單數(shù)據(jù)源
添加依賴
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.21</version>
</dependency>
yml配置
spring:
datasource:
name: 名稱
url: 地址
username: 用戶名
password: 加密后的密碼
driver-class-name: com.mysql.cj.jdbc.Driver
# druid
type: com.alibaba.druid.pool.DruidDataSource
druid:
#特別提示:配置數(shù)據(jù)庫加密 config這個不能忘掉
filters: stat,wall,config
use-global-data-source-stat: true
# 開啟解密config.decrypt=true; 公鑰:config.decrypt.key
connect-properties:
druid.stat.mergeSql: true
druid.stat.slowSqlMillis: 5000
druid.stat.logSlowSql: true
config.decrypt: true
config.decrypt.key: 公鑰
# 連接池的配置信息
# 初始化大小,最小空閑連接數(shù),最大活躍數(shù)
initial-size: 5
min-idle: 5
maxActive: 20
# 配置獲取連接等待超時的時間
maxWait: 60000
# 配置間隔多久才進行一次檢測,檢測需要關(guān)閉的空閑連接,單位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一個連接在池中最小生存的時間,單位是毫秒
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
# 打開PSCache,并且指定每個連接上PSCache的大小
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
四:多數(shù)據(jù)源
添加依賴
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.21</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>2.5.3</version>
</dependency>
啟動類配置
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
eg:

yml配置
spring:
datasource:
dynamic:
# 默認數(shù)據(jù)源
primary: CLOUD
datasource:
CLOUD:
url: 數(shù)據(jù)庫地址
username: 用戶名
password: 加密后的密碼
driver-class-name: com.mysql.cj.jdbc.Driver
druid:
public-key: 加密后的公鑰
WAREHOUSE:
driver-class-name: com.mysql.cj.jdbc.Driver
url: 數(shù)據(jù)庫地址
username: 用戶名
password: 加密后的密碼
druid:
public-key: 加密后的公鑰
到此這篇關(guān)于Springboot2 集成 druid 數(shù)據(jù)庫密碼加密的文章就介紹到這了,更多相關(guān)Springboot數(shù)據(jù)庫密碼加密內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java?IO篇之Reactor?網(wǎng)絡(luò)模型的概念
Reactor?模式也叫做反應(yīng)器設(shè)計模式,是一種為處理服務(wù)請求并發(fā)提交到一個或者多個服務(wù)處理器的事件設(shè)計模式,Reactor?模式主要由?Reactor?和處理器?Handler?這兩個核心部分組成,本文給大家介紹Java?IO篇之Reactor?網(wǎng)絡(luò)模型的概念,感興趣的朋友一起看看吧2022-01-01
解決RestTemplate 請求url中包含百分號 會被轉(zhuǎn)義成25的問題
這篇文章主要介紹了解決RestTemplate 請求url中包含百分號 會被轉(zhuǎn)義成25的問題,具有很好的參考價值,希望對大家有所幫助。2021-10-10
springboot?@PostConstruct無效的解決
這篇文章主要介紹了springboot?@PostConstruct無效的解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11

