前言:在项目中需要用到动态切换多数据源,查阅Mybatis-plus文档得知可以通过@DS注解,但该方法主要针对不同内容的数据源,而目前场景是相同内容的数据库需要在运行时根据请求头动态切换,因此文档方法不适用。 注意,不要使用dynamic-datasource-spring-boot-starter依赖包。 一、动态多数据源的场景 应用不拆,数据库拆 读写分离 二、动态多数据源的实现 网上文章非常多,大体思路都差不多,笔者在这里不重复放置代码了,例如:《springboot 中动态切换数据源》 不过目前找到的文章方法在项目整合了Mybatis-plus的情况下基本都有问题,以下是这几天遇到的问题和解决方案。 三、问题与解决方案 1.
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with Globalconfig.set MetaObject
Contact Globalconfig.set MetaObject, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck RackActions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Articles
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with Globalconfig.set MetaObject
Contact Globalconfig.set MetaObject, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack