# read_write_seperate **Repository Path**: yuw123/read_write_seperate ## Basic Information - **Project Name**: read_write_seperate - **Description**: 读写分离实践 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-05-28 - **Last Updated**: 2021-05-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # read_write_seperate ## 介绍 读写分离实践 ## 原理 - AbstractRoutingDataSource 内部有个Map resolvedDataSources - determineTargetDataSource 通过 determineCurrentLookupKey 获得Key,进入从map取得DataSource ## 步骤 - 在setProperties前 设置TargetDataSource - TargetDataSource 会转成 ResolvedDataSources - 利用ThreadLocal设置读写库 - 重写determineCurrentLookupKey 根据ThreadLocal 中设置的键 选择读写数据库 - 利用AOP在Spring提交事务前确定数据源