如何使用2个数据库在Spring Boot应用中动态获取数据库连接?
我是春季的新手,考虑一个在弹簧应用中使用两个数据库并且配置的情况(一个是mysql,另一个是post -gre),一项服务在mysql中使用表,而另一个服务在post -gre中使用表格,现在我想知道如何在运行时为他们提供所需的数据库连接?
任何帮助都将受到赞赏。 tia
I am very new to spring, Consider a situation where two databases are being used in a spring app and they are configured (one is MySql and the other is PostGre), one service uses a table in MySql and other service uses a table in PostGre, now I want to know how do I provide them the required database connection during runtime?
Any help is appreciated. TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此答案说明了如何为单个Spring Boot应用程序配置两个数据源。
另外, this 教程用详细的示例解释了相同的概念。
可以通过从主数据库上的每个表中获取所有对象,删除ID值并将其保存到第二个DB来完成复制过程。
This answer explains how to configure two data sources for a single Spring Boot application.
Also, this tutorial explains the same concept with a detailed example.
The copying procedure could be done by fetching all the objects from each table on the main DB, deleting id values, and saving them to the second DB.