Issue
I have configured Spring JPA to work with multiple data sources following this example. Spring JPA – Multiple Databases
It works as expected but since I want to use different data sources but with the same repositories there is an issue. When I try to use "Declarative Transaction Management" on my services and specify which transaction I am going to use the primary transaction or secondary one the transaction annotation is ignoring it. So in this case it is using the second one. However, both of the beans "PlatformTransactionManager" are created but when it comes to using in "@Transactional" I am not able to make the transaction work with the bean I have specified. So it seems that @Transactional is ignoring the bean name since they have the same repositories. Is there any way how can I use declarative transactions as I am trying to do it? As I have seen it can be done with Programmatic Transaction Management but it will cost me to change the whole code on my services since I have been using only declarative transactions.
Solution
The answer was found: It can be done by extending AbstractRoutingDataSource class of spring.
Answered By - java programming
Answer Checked By - David Goodson (JavaFixing Volunteer)