dynamic-datasource detect druid publicKey,It is highly recommended that you use the built-in encryption method
使用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日志。
dynamic-datasource detect druid publicKey,It is highly recommended that you use the built-in encryption method的更多相关文章
- SpringBoot(七):集成DataSource 与 Druid监控配置
绑定DataSource:Spring Boot默认的数据源是:org.apache.tomcat.jdbc.pool.DataSource,Druid是Java语言中最好的数据库连接池,并且能够提供 ...
- springboot~集成DataSource 与 Druid监控配置
介绍 Druid首先是一个数据库连接池.Druid是目前最好的数据库连接池,在功能.性能.扩展性方面,都超过其他数据库连接池,Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模部 ...
- MyBatis在非Spring环境下第三方DataSource设置-Druid篇
首先在ITEye上面看到一个同标题文章,在此说明,此文并非转载自 http://iintothewind.iteye.com/blog/2069522 ,因为这篇文章根本就是错误的,照着上面做,工程可 ...
- Spring Dynamic DataSource Routing
Use AbstractRoutingDataSource to dynamicly switch datasources, see http://spring.io/blog/2007/01/23/ ...
- spring boot:用dynamic-datasource-spring-boot-starter配置druid多数据源(spring boot 2.3.3)
一,dynamic-datasource-spring-boot-starter的用途? 1,dynamic-datasource-spring-boot-starter 是一个基于springboo ...
- spring boot:用dynamic-datasource-spring-boot-starter配置多数据源访问seata(seata 1.3.0 / spring boot 2.3.3)
一,dynamic-datasource-spring-boot-starter的优势? 1,dynamic-datasource-spring-boot-starter 是一个基于springboo ...
- alibaba/druid 下的 密码加密
使用ConfigFilter cliangch edited this page on 3 Feb · 12 revisions ConfigFilter的作用包括: 从配置文件中读取配置 从远程ht ...
- Spring Boot使用Druid连接池基本配置
以下为Spring Boot配置Druid 一.pom.xml配置 <dependency> <groupId>com.alibaba</groupId> < ...
- Druid + spring 配置数据库连接池
1. Druid的简介 Druid是一个数据库连接池.Druid是目前最好的数据库连接池,在功能.性能.扩展性方面,都超过其他数据库连接池,包括DBCP.C3P0.BoneCP.Proxool.JBo ...
- Spring Boot + Druid 多数据源绑定
date: 2019-12-19 14:40:00 updated: 2019-12-19 15:10:00 Spring Boot + Druid 多数据源绑定 版本环境:Spring Boot 2 ...
随机推荐
- 使用C#构建一个同时问多个LLM并总结的小工具
前言 在AI编程时代,如果自己能够知道一些可行的解决方案,那么描述清楚交给AI,可以有很大的帮助. 但是我们往往不知道真正可行的解决方案是什么? 我自己有过这样的经历,遇到一个需求,我不知道有哪些解决 ...
- 遇到的问题之“web container destroy and kill the job.-Web容器销毁和终止作业”
一.问题 JobThread toStop, stopReason:web container destroy and kill the job. 2023-11-22 18:10:10 [com.x ...
- SQL 强化练习 (十三)
这几天都在整帆软报表, 还要弄 RPA ... 咱说呢, 这些破玩意, 是提升了业务人员的工作效率, 但, 极大降低了我的工作效率, 明明写代码就能解决, 非要各种 点点点... 文档也不全, 就很难 ...
- 内网服务器离线安装部署 Ollama
一.安装 Ollama 1.官网下载地址:Releases · ollama/ollama 2.cd至下载目录 3.执行二进制文件安装 sudo tar -C /usr -xzf ollama-lin ...
- React-Native开发鸿蒙NEXT-多bundle的加载
.markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...
- Intellij Idea 通过svn或者git提交代码时速度慢的解决办法
问题分析:在使用 IntelliJ IDEA 操作Git的时候,Git响应速度特别满,等待差不多10秒.甚至更长时间才完成操作,真是等的花儿都谢了. 解决方案:更改IntelliJ IDE ...
- 「Log」CSP-S 2023 游记
Day 0 什么题也没写,稍微复习了一下,晚上打了些板子. 整个人处于放空状态. Day 1 早上睡了懒觉,老爹早就给我点了肯德基早餐. 边吃早餐边看番,吃完了去群里水了一水,讨论了点杂七杂八的东西, ...
- Django中的文件操作
一.静态文件的加载 1.使用步骤 ①.在工程目录下创建static目录,创建css/js/images等目录,并添加相关资源 ②.在settings.py中配置STATICFILES_DIRS STA ...
- kubernetes实用插件管理
插件链接:https://kubernetes.io/zh-cn/docs/tasks/extend-kubectl/kubectl-plugins/
- 深入浅出容器学习--Docker数据卷
一.Docker数据卷 Docker镜像是由多个文件系统(只读层)叠加而成,当启动一个容器的时候,Docker会加载只读镜像层并在其上(镜像栈顶部)添加一个读写层.如果运行中的容器修改了现有的一个已经 ...