如何使用2个数据库在Spring Boot应用中动态获取数据库连接?

发布于 2025-02-01 10:12:25 字数 150 浏览 2 评论 0原文

我是春季的新手,考虑一个在弹簧应用中使用两个数据库并且配置的情况(一个是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一萌ing 2025-02-08 10:12:25

此答案说明了如何为单个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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文