Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EnableTransactionManagement for multiple databases in Spring

I have an application that needs to access two databases. I am trying to use Spring transactions to accomplish this.

1) Since I have two databases and a transaction manager takes a datasource as a parameter, must I configure two transaction managers, with each @Transactional specifying the correct transaction manager to use? ex: @Transcational("database1"), @Transactional("database2").

2) Since @EnableTransactionManagement will look for a single transaction manager to use for all transactions, I do not think I can use this annotation. Is that the case? Can I still utilize transactions with @Transactional("database") and no @EnableTransactionManagement?

like image 434
tux Avatar asked Jun 17 '26 19:06

tux


1 Answers

Please look to the relevant documentation: http://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/transaction.html#tx-multiple-tx-mgrs-with-attransactional

like image 140
Gokhan Oner Avatar answered Jun 20 '26 13:06

Gokhan Oner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!