Multiple Databases Using the Same Domain Models Using Spring Boot and Spring JPA Data

In my Spring boot project, I am writing a service to import selected data from one environment to another. (for example, copy one entry to dev on prod) As for read , in order to configure several data sources, I need to create different JPA repositories and domain models. But since the db structures are identical in each data source, it will just be code repetition. Is there a better practice for copying data from one database to another using Spring JPA data?

+4
source share
1 answer

One way to solve this problem without adding the many complexities of data sources would be to create two different spring profiles (one for each data source), and then run 2 instances of the application, one with each spring. profile. Read the data from one, then pass the data to the second (via REST or something else) to insert it. It also creates reusable services for each data source if you need access elsewhere.

There are ways to use sources with multiple data, but I always thought that they were too complex for what I needed.

0
source

Source: https://habr.com/ru/post/1682155/


All Articles