druid 密码加密配置

使用druid 的spring boot starter 配置

  • application.yml
spring:
  datasource:
    druid:
      url: jdbc:postgresql://127.0.0.1:5432/test
      username: test
      password: l7LrIhkDLct9BTd6eVVS3tsAwDYkwX4+e/zVGTk2Nbu110JN1Laa7Yv5/632N6zGlXhVTVynt4xnIS0+GsxWl1==
      driver-class-name: org.postgresql.Driver
      maxActive: 10
      minIdle: 1
      initialSize: 3
      connection-properties: config.decrypt=true;config.decrypt.key=${spring.datasource.druid.filter.config.public-key}
      filter:
        config:
          enabled: true
          public-key: MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMsftVrO3eWNi/uXUkmUkqwmr86SjSbBDDi9NBoyfS+PlP2vuMsg62wTW2xGxg8csmOQsPHFbZKSfh99UJlyYtUCAwEAAQ==
  • 需要注意的点
    • connection-properties 配置,durid 使用的set 方法配置的
      	public void setConnectionProperties(String connectionProperties) {
          if (connectionProperties == null || connectionProperties.trim().length() == 0) {
              setConnectProperties(null);
              return;
          }
      
          String[] entries = connectionProperties.split(";");
          Properties properties = new Properties();
          for (int i = 0; i < entries.length; i++) {
              String entry = entries[i];
              if (entry.length() > 0) {
                  int index = entry.indexOf('=');
                  if (index > 0) {
                      String name = entry.substring(0, index);
                      String value = entry.substring(index + 1);
                      properties.setProperty(name, value);
                  } else {
                      // no value is empty string which is how java.util.Properties works
                      properties.setProperty(entry, "");
                  }
              }
          }
      
          setConnectProperties(properties);
      }
      
    • 生成密码java -cp druid-1.1.10.jar com.alibaba.druid.filter.config.ConfigTools xxx
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值