spring-boot-starter-jta-atomikos in practise

Dmitry picture Dmitry · Aug 15, 2015 · Viewed 8.2k times · Source

I'm trying to use Atomikos for distributed transactions in my spring boot application. It will interact with the two databases.

I found an example in which the author uses Atomicos. Starting with version 1.2 spring boot supports Atomicos.

I have several questions:

  1. What part of the example configuration can be removed, if an application has spring-boot-starter-jta-atomikos dependency?
  2. What will happen when an application performs an operation with only one database? i.e. Do I need something extra to specify which transactions should be distributed and which are local or will it be automatically detected? I want to avoid an overhead in this case.

Thanks!

Answer

Stephane Nicoll picture Stephane Nicoll · Aug 16, 2015

Spring Boot will auto-configure the JtaTransactionManager for you and bind it properly to your entity manager or JMS message listener, if any. Check the documentation for more details. A safe way of starting is to not write any configuration at all and see what you need to customize via properties or custom configuration.

That being said, Spring Boot has no auto-configuration support for several databases. If you want to configure a project with two databases, you'll have to do it yourself; this sample project shows you how you can do it with JPA and a local transaction manager. You can easily port it to JTA with Atomikos based on the example you've referenced.

You can't change the transaction manager at runtime (i.e. based on the fact that your thread is using only one database). I guess that the transaction manager itself has an optimization for such a case, not running a full 2PC if it does not have to.