Forget the Spring Package.
Suppose you need to write an application service that is read from a single data source1 and write to a data source2, what do you need to do?
Distributed transaction is the answer for you. This, of course, is due to additional configurations. If you are in a J2EE container (Websphere, Weblogic, JBoss, etc.), then the transaction manager that they provide should be able to handle distributed transactions. You should find the appropriate Spring TransactionManager implementation for each of these platforms. You need to configure only the data source (which should also be in the container) to use drivers that support XA, and in your application using the appropriate transaction manager and search for data sources that support XA using JNDI
However, if you cannot rely on a container (for example, you are writing a standalone application, etc.), you will need to find a transaction manager that is capable of this. Atomikos is one of the most famous free JTA / XA libraries.
Of course, if you are one hundred percent sure that all transactional actions will be in datasource2, you can consider using the data transaction manager only for datasource2, but to be honest, this is not the preferred approach that I propose.
source share