How to configure Spring boot for work with two databases?

后端 未结 2 999
旧巷少年郎
旧巷少年郎 2021-02-05 17:14

I am using Spring Boot 2.X with Hibernate 5 to connect two different MySQL databases (Bar and Foo) on different servers. I am trying t

2条回答
  •  不知归路
    2021-02-05 17:48

    Two databases (aka "catalogs") on the same server? Use only one connection. Then reference thus:

    Foo.table1
    Bar.table2
    

    Use that syntax wherever you would have a simple table name.

    Different servers

    It gets messy if the data is not in the same machine. A couple of ideas:

    • Fetch the data from each catalog, then manipulate in application code. The framework probably has no hooks for doing anything to both servers at the same time.
    • Use MariaDB and its FEDERATEDX Engine.

提交回复
热议问题