Okay, I've read quite a lot of post around this and read spring boot documentation on this but never really got an answer which is cleaner approach.
Here my use case: We have like 100-200 oracle entities and we're using JPARepository interface to query them. Now we need to make sure read db is used for read calls and write db should be used for any writes.
We have a spring boot application, using HikariCP datasource and configured it using @EnableTransactionManagement, @EnableJpaRepositories passing reference of entity manager, transaction manager and base packages to scan.
I've created two configuration files, one with ReadConfiguration and one with WriteConfiguration. Now problem is, we have code in a standard OO way where we have service and repository layer. Different services are injecting various repositories. Each repository interface is extending JpaRepository and that interface is autowired in lot of service classes.
What I want to achieve is to use the same repository layer but somehow repository layer should know automatically that if it's a read call then use read datasource and if it's a write call use a write data source.
One of the solution is to use some kind of way to hack the proxy implementation of repository to have some logic to see if it's read call then use this read datasource if it's a write call then use write datasource. Has anyone solved this in a this way? Essentially what I need is to route call to datasource depending on the method call. If method is doing some read operation then I need to make sure it use read datasource or else use write datasource.
Can anyone point in some direction on how to achieve with this kind of architecture without writing new repository layer for read and write.
Thanks.