We have a use-case where we want to talk to different databases which support transactions and want to do it via the annotation that spring provides.
The way I see this annotation works is that it picks the default implementation of PlatformTransactionManager
with the DataSource bean defined by the client and talks to that persistence layer.
So, to talk to another data source, I will have to provide a TransactionManager
which overrides its doBegin
method with the help of new data source.
But the problem here is that if I do that, there is no way for the @Transaction
annotation to know about which data source to pick (I am not able to see how bootstrap works in these cases because I don't see a way bean conflict could arise - maybe I am missing something here).
One alternative I can think of is to create a new annotation @DataSourceAwareTransaction which accepts a parameter for the default data source and logic gets written in the new annotation.
The issue with this approach is that I will have to change all the existing code to move from @Transaction to @DataSourceAwareTransaction.
The approach I am describing looks reasonable enough? Does anyone have any better ideas?
Thanks!