Springboot2 集成 druid 加密數(shù)據(jù)庫密碼的配置方法
一:環(huán)境
springboot 2.x
druid 1.1.21
二:druid加密數(shù)據(jù)庫密碼
本地下載druid-1.1.21.jar包,運(yùn)行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ù)庫密碼
運(yùn)行成功輸出
privateKey:MIIBVAIBAD...
publicKey:MFwwDQYJKo...
password:PNd/zcG+JEn...
將得到的publicKey、password分別填充進(jìn)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
# 配置間隔多久才進(jìn)行一次檢測,檢測需要關(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:
# 默認(rèn)數(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使用Collections.sort對中文進(jìn)行排序方式
這篇文章主要介紹了Java使用Collections.sort對中文進(jìn)行排序方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-11-11
Java的內(nèi)存區(qū)域與內(nèi)存溢出異常你了解嗎
這篇文章主要為大家詳細(xì)介紹了Java的內(nèi)存區(qū)域與內(nèi)存溢出異常,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-03-03

