'Dynamically change data source connection at runtime in Spring Boot

I have a spring-boot application with one database. Now I would like to integrate the possibility to copy some data from this database to another database. The connection to the second database should be done during runtime. I insert in my frontend the second database connection and start the copy from the first database to the second. The two databases have the same tables and I would like to use the same repositories. Is it possible to do that? If yes, do you know some code example or documentation? I'm trying to find the correct approach to do that.

Thank you!



Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gsan