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 ...
随机推荐
- 遇到的问题之"数据库编写SQL-》子查询中加入limit报错:This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'"
一.问题 > 1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' 二. ...
- Grid 布局-子项补充及常用布局
上篇我们介绍了 Grid 布局容器项的内容, 看上去属性很多, 其实并没有, 记住关键的概念和简写就行啦. 因为是二维的, 这个属性的数量就比 flex 要多很多哦, 但其实真正也没有常用那没多啦. ...
- TVMC python:一种TVM的高级API
Step 0: Imports from tvm.driver import tvmc Step 1: Load a model 下载模型: wget https://github.com/onnx/ ...
- github每次提交代码都要登录
原因:不要使用https的方式克隆代码,而是用git. 查看源 git remote -v 删除源 git remote rm origin 重新添加项目源(origin后面改成自己的): git r ...
- 【公众号搬运】React-Native开发鸿蒙NEXT(7)-上线
.markdown-body { line-height: 1.75; font-weight: 400; font-size: 16px; overflow-x: hidden; color: rg ...
- CentOS 7.* 安装 python3.8.2 python3.10.2 步骤
CentOS 7系列 安装 python3.8.2 步骤 1.在python官网下载linux源码包 地址:https://www.python.org/ftp/python/3.8.3/Python ...
- LUNARiA
本文同步发布于我的网站 也算是头一次在没有任何安利和剧透,仅在看了简介的情况下就直接下单并开始游玩一部gal了.果然,没有给我留下什么遗憾呢. 游玩日志 SKYOUT-FOREVER <LUNA ...
- Linux服务器(CentOS/Ubuntu)接口Bond模式详解、配置指南及交换机对应接口的配置示例
以下是关于Linux服务器(CentOS/Ubuntu)与交换机对接的接口Bond模式详解.配置指南及交换机配置示例(思科/华为/华三) 的全面说明: 一.Linux Bonding 模式对比 模式 ...
- Openmv简明使用教程
Openmv简明使用教程 写在前面 本教程主要目的是指明学习资源在哪,可以怎么学,不教具体怎么使用,因为没有什么教程比官网上的教程更详细了,希望大家看完这篇文章后,能对如何学习使用Openmv有一个清 ...
- js加密手机号码中间四位方法
一.实现效果: 二.方法代码封装: 方法一: //encryptPhoneNumber.ts /** * 加密手机号码中间四位 * @param phone 手机号 * @returns { stri ...