Code Monkey home page Code Monkey logo

Comments (8)

yosaku01 avatar yosaku01 commented on May 26, 2024

http://blog.csdn.net/u011126891/article/details/79014741
这是我的解决方案,你看一下对你有帮助没有?

from springboot-dynamicdatasource.

helloworlde avatar helloworlde commented on May 26, 2024

是可以的,也可以参考
https://github.com/YHYR/Mybatis
https://www.jianshu.com/p/4df0daa1cd68
实现,稍后会把这些加上去

from springboot-dynamicdatasource.

yosaku01 avatar yosaku01 commented on May 26, 2024

用我的方案,MybatisHelper貌似会失效,可能需要调整MybatisHelper的代码

from springboot-dynamicdatasource.

huayanYu avatar huayanYu commented on May 26, 2024

可以试试 https://github.com/baomidou/dynamic-datasource-spring-boot-starter

from springboot-dynamicdatasource.

gatspy avatar gatspy commented on May 26, 2024

我也蛮需要用类似,或者配置中心的方式实现多租户多库的数据源切换啊。怎么解呢?

from springboot-dynamicdatasource.

helloworlde avatar helloworlde commented on May 26, 2024

我也蛮需要用类似,或者配置中心的方式实现多租户多库的数据源切换啊。怎么解呢?

可以用 SpringConfig + SpringCloud Bus 实现,当配置更新之后通过 SpringCloud Bus 通知应用更新配置

from springboot-dynamicdatasource.

gatspy avatar gatspy commented on May 26, 2024

@helloworlde 谢谢您的回复。
更新配置应该不是问题。
在配置中心可以配置所有租户对应的数据库和数据源(目前是一个租户一个独立数据库),然后从api接口中获取到当前租户的id后呢? 怎么配置来切换数据源?还有就是租户的读写分离呢?

from springboot-dynamicdatasource.

helloworlde avatar helloworlde commented on May 26, 2024

@gatspy
其实真正切换数据源的实现是通过修改当前线程的本地变量实现的,可以暴露 API 调用切换数据源的方法,读写分离也是通过设置不同的数据源Bean 名称,都可以使用这个方法来实现

from springboot-dynamicdatasource.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.