# multisource **Repository Path**: lwlgit/multisource ## Basic Information - **Project Name**: multisource - **Description**: spring boot 多租户数据库切换 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2017-12-06 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # multisource spring boot 多租户数据库切换 # 原理 ## InheritableThreadLocal 有程序入口处将租户ID存入 InheritableThreadLocal 中 ## 自定义DataSource 1、自定义MultiDataSource类,implements DataSource 2、重写getConnection() 方法, 在此方法中 获取当前租户ID并返回对应租户数据库的Connection对象 ![Image text](https://gitee.com/lwlgit/multisource/raw/master/readme/pic01.png) ![Image text](https://gitee.com/lwlgit/multisource/raw/master/readme/pic2.png)