Spring Boot 2 with Multiple DataSources

Postgres Setup

Write PostgresSql on port 5432 — Docker-Compose
Read PostgresSql on port 5433 — Docker-Compose

Spring Boot Setup

select web, data-jpa, lombok, postgresDriver
on application.yml, datasource-write is the Master(Primary) and datasource-read is the Slave (Secondary)
Write package: “com.ehsaniara.multidatasource.repository.writeRepository”
Read Package: “com.ehsaniara.multidatasource.repository.readRepository”
When you run the application you can see 2 Persistence Unit as Read and Write



Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store