Search code examples
spring-bootjtaspring-jmsatomikos

With spring boot, how does it detect a JTA environment?


I'm trying to enable JTA with spring boot so that JPA and JMS will roll back together. All docs point to http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-jta.html and it states

When a JTA environment is detected, Spring’s JtaTransactionManager will be used to manage transactions.

What is meant by "JTA environment is detected"?

I ask because I think that is what is tripping me up. I added dependencies for Atomikos, but jmsTemplate.isSessionTransacted() returns false. I am assuming I haven't properly marked my environment as JTA. I'm running with embedded tomcat.

What I am experiencing is the database changes are being rolledback with the transaction, but not the JMS messages.

UPDATE:

The part about sessionTransacted was not related. It was my misunderstanding.


Solution

  • A JTA environment is detected when a supported transaction manager is on the classpath (Atomikos or Bitronix in 1.3, and also Narayana in 1.4) or because a javax.transaction.TransactionManager is available in JNDI (typically because you've deployed your Boot app to a Java EE container).

    I think you have misunderstood the purpose of the sessionTransacted flag on JmsTemplate. It's used when creating a new session (Connection.createSession), however the transacted value that's passed to createSession is ignored when you're running in a JTA environment.