一.前言
为了应对数据库服务器的压力,在数据库的架构上需要进行读写分离的架构,代码也需要支持读写分离。
二.实践操作
2.1 yml 配置
spring:
datasource:
master:
url: jdbc:mysql://xxxxxxx:3306/xxxxxx?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useAffectedRows=true
username: xxxx
password: xxx
driver-class-name: com.mysql.cj.jdbc.Driver
#从库
slave:
url: jdbc:mysql://localhost:3306/xxxx?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useAffectedRows=true
username: xxxxx
password: xxxxx
driver-class-name: com.mysql.cj.jdbc.Driver
2.2 枚举
public enum EDataSource {
MASTER("master", "主库"),
SLAVE("slave", "从库");
private String code;
private String desc;
EDataSource(String code, String desc) {
this.code = code;
this.desc = desc;
}
publi

最低0.47元/天 解锁文章
8106

被折叠的 条评论
为什么被折叠?



