druid springboot2.1.4多数据源数据库连接加密不生效?

mkh04yzy  于 2022-10-23  发布在  Druid
关注(0)|答案(3)|浏览(292)

环境:springboot2.1.4
druid-spring-boot-starter 1.1.16

配置#ds0
spring.datasource.druid.ds0.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.druid.ds0.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.druid.ds0.url=jdbc:oracle:thin:@*******
spring.datasource.druid.ds0.username=*****
spring.datasource.druid.ds0.password=****
spring.datasource.druid.ds0.public-key=***
spring.datasource.druid.ds0.connection-properties=config.decrypt=true;config.decrypt.key=${spring.datasource.druid.ds0.public-key}
spring.datasource.druid.ds0.filter.config.enabled=true

代码:
@primary
@bean(name = "ds0DruidDataSource")
@ConfigurationProperties(prefix = "spring.datasource.druid.ds0")
public DruidDataSource ds0DruidDataSource()
{
return DruidDataSourceBuilder.create().build();

}

加密没生效,用明文能成功连接数据库

kx7yvsdv

kx7yvsdv1#

老哥请问解决了吗

mpgws1up

mpgws1up2#

spring2.1.16 + druid1.1.18 可以这样设置

public-key=MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL9FQiaJQb93YLQbOAjhhMwBomJhlYgl7ZaoxamN5N1+wOhyCjkdtAD1MQxCywdsTPwZWYwegjdM8CMWfqM2XuMCAwEAAQ==

数据源一

ds1.password=kiTcvppcKK3zHqHTTegxqb+fJ4zMmiZuACK1k0uR6Uh6lMNZVhoxqKKK3173DDpEM0R79ZsITkkBz2ocrlaI+w==
ds1.filters=config,stat,wall
ds1.filter.config.enabled=true
ds1.connection-properties=config.decrypt=true;config.decrypt.key=${public-key}

数据源二

ds2.password=lHZOsKHQvdLPqKKq3TrCS4EQrJbbTSh29c4JAXc1CwYvuxHxgFeY6v6/qXaNSeSO9Nmd6Ddwbnzj9ys0zviW9w==
ds2.filters=config,stat,wall
ds2.filter.config.enabled=true
ds2.connection-properties=config.decrypt=true;config.decrypt.key=${public-key}

lmvvr0a8

lmvvr0a83#

connection-properties=config.decrypt=true;config.decrypt.key=${spring.datasource.druid.ds0.public-key}
filter.config.enabled=true
这两个的配置的层级前缀需要是 spring.datasource.druid.
参考 com.alibaba.druid.spring.boot.autoconfigure.stat.DruidFilterConfiguration

相关问题