mysql读写分离sharejdbc_Spring Boot + Sharding-JDBC实现读写分离和数据脱敏

Spring Boot + Sharding-JDBC实现读写分离和数据脱敏

使用官网上的读写分离配置+脱敏配置,发现脱敏没有效果,

尝试了手动配置数据源,测试有效。

注:如果脱敏字段的值为null时,脱敏会报空指针异常。

1.pom文件

org.apache.commons

commons-dbcp2

2.6.0

org.apache.shardingsphere

sharding-jdbc-core

4.0.0-RC1

2.添加property配置

datasource.master.type=org.apache.commons.dbcp2.BasicDataSource

datasource.master.driver-class-name=com.mysql.jdbc.Driver

datasource.master.url=jdbc:mysql://192.168.1.196:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false

datasource.master.username=

datasource.master.password=

datasource.slave0.type=org.apache.commons.dbcp2.BasicDataSource

datasource.slave0.driver-class-name=com.mysql.jdbc.Driver

datasource.slave0.url=jdbc:mysql://192.168.1.195:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false

datasource.slave0.username=

datasource.slave0.password=

#加密方式 自带AES和MD5 可自定义

encrypt.type=AES

#加密字段,多个用,分隔,格式:表名.字段名

encrypt.qualifiedColumns=

#AES加密所需密钥

encrypt.aes.key.value=

3.配置数据源

import org.apache.commons.dbcp2.BasicDataSource;

import org.apache.shardingsphere.api.config.encryptor.EncryptRuleConfiguration;

import org.apache.shardingsphere.api.config.encryptor.EncryptorRuleConfiguration;

import org.apache.shardingsphere.api.config.masterslave.MasterSlaveRuleConfiguration;

import org.apache.shardingsphere.shardingjdbc.api.EncryptDataSourceFactory;

import org.apache.shardingsphere.shardingjdbc.api.MasterSlaveDataSourceFactor

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值