首页 > 基础资料 博客日记
dynamic-datasource detect druid publicKey,It is highly recommended that you use the built-in encryption method
2025-06-24 16:30:01基础资料围观10次
文章dynamic-datasource detect druid publicKey,It is highly recommended that you use the built-in encryption method分享给大家,欢迎收藏Java资料网,专注分享技术知识
使用druid-spring-boot-starter 1.2.11作为数据库连接池 + dynamic-datasource-spring-boot-starter 3.4.1作为多数据源支持,并且使用了druid的数据库密钥加密功能,启动项目发现日志中有如下日志:
[2024-10-31 15:42:55.343] - [INFO ] - [15336] - [240E04791E60243BB7BE00FEE00CC8F33BE822D8CFE09DDE00D10000] - [main] - [c.b.d.d.s.b.a.d.DruidConfig-255] - dynamic-datasource detect druid publicKey,It is highly recommended that you use the built-in encryption method
https://dynamic-datasource.com/guide/advance/Encode.html
yml中数据源的配置信息为:
spring:
datasource:
# 多数据源配置
dynamic:
primary: db1
strict: true
datasource:
# 第一个数据源
db1:
url: jdbc:mysql://localhost:3306/db1?...
username: root
password: xxx
druid:
...
min-evictable-idle-time-millis: 300000
max-evictable-idle-time-millis: 300000
# 公钥
public-key: xxx
# 第二个数据源
db2:
url: jdbc:mysql://localhost:3306/db2?...
username: root
password: xxx
druid:
...
min-evictable-idle-time-millis: 300000
max-evictable-idle-time-millis: 300000
# 公钥
public-key: xxx
根据日志在com.baomidou.dynamic.datasource.spring.boot.autoconfigure.druid.DruidConfig类中定位到了日志输出位置,这个类是druid数据库连接池的配置类,
Properties connectProperties = connectionProperties == null ? g.getConnectionProperties() : connectionProperties;
if (publicKey != null && publicKey.length() > 0) {
if (connectProperties == null) {
connectProperties = new Properties();
}
log.info("dynamic-datasource detect druid publicKey,It is highly recommended that you use the built-in encryption method \n " +
"https://dynamic-datasource.com/guide/advance/Encode.html");
connectProperties.setProperty("config.decrypt", "true");
connectProperties.setProperty("config.decrypt.key", publicKey);
}
this.connectionProperties = connectProperties;
发现如果druid的公钥配置在publicKey下就会触发日志输出,并且会设置两个配置属性到connectProperties中,一个是config.decrypt,一个是config.decrypt.key。
修改yml中的配置,不在publicKey下配置公钥,而是配置到connectionProperties下:
spring:
datasource:
# 多数据源配置
dynamic:
primary: db1
strict: true
datasource:
# 第一个数据源
db1:
url: jdbc:mysql://localhost:3306/db1?...
username: root
password: xxx
druid:
...
min-evictable-idle-time-millis: 300000
max-evictable-idle-time-millis: 300000
# 公钥
connection-properties:
"config.decrypt": "true"
"config.decrypt.key": xxx
# 第二个数据源
db2:
url: jdbc:mysql://localhost:3306/db2?...
username: root
password: xxx
druid:
...
min-evictable-idle-time-millis: 300000
max-evictable-idle-time-millis: 300000
# 公钥
connection-properties:
"config.decrypt": "true"
"config.decrypt.key": xxx
启动项目发现数据库连接失败:
Caused by: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
再次在DruidConfig类中查看publicKey使用到的位置,发现:
//filters单独处理,默认了stat,wall
String filters = this.filters == null ? g.getFilters() : this.filters;
if (filters == null) {
filters = "stat";
}
if (publicKey != null && publicKey.length() > 0 && !filters.contains("config")) {
filters += ",config";
}
properties.setProperty(FILTERS, filters);
原来还需要设置druid的filters属性,修改yml中的配置为:
spring:
datasource:
# 多数据源配置
dynamic:
primary: db1
strict: true
datasource:
# 第一个数据源
db1:
url: jdbc:mysql://localhost:3306/db1?...
username: root
password: xxx
druid:
...
min-evictable-idle-time-millis: 300000
max-evictable-idle-time-millis: 300000
filters: "stat,config"
# 公钥
connection-properties:
"config.decrypt": "true"
"config.decrypt.key": xxx
# 第二个数据源
db2:
url: jdbc:mysql://localhost:3306/db2?...
username: root
password: xxx
druid:
...
min-evictable-idle-time-millis: 300000
max-evictable-idle-time-millis: 300000
filters: "stat,config"
# 公钥
connection-properties:
"config.decrypt": "true"
"config.decrypt.key": xxx
再次启动项目,成功启动且没有再出现dynamic-datasource detect druid publicKey,It is highly recommended that you use the built-in encryption method日志。
文章来源:https://www.cnblogs.com/imadc/p/18517970
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
标签:
上一篇:什么是ollama?如何安装ollama和应用
下一篇:没有了