Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

How to use BTM as the transaction manager with Spring 2.x

These instructions have been verified against BTM 1.1.


Table of Contents

Step 1: Copy the BTM jars

Include the following jars from the BTM distribution into your classpath:

  • btm-1.1.jar
  • geronimo-spec-jta-1.0.1B-rc4.jar
  • slf4j-jdk14.jar (or any other one available here)

Step 2: Configure connection pools beans

The first things you will need to configure are the connection pools.


titleAPI-created pools

Since the pools are created via the BTM API (ie: not with ResourceLoader) it is up to the API user to manage the lifecycle of the pools, mainly calling init() before usage and close() at shutdown.
This is why the two init-method and destroy-method attributes are set: to have Spring take care of that lifecycle.

Step 3: Configure BTM beans

The second thing you need to do is configure beans for BTM.


titleInitialization ordering

The TransactionManagerServices.getTransactionManager() call will initialize BTM. Before this, all connection pools should have been created and the configuration properties should have been set.
This is why the depends-on attribute is set: the BitronixTransactionManager bean must not be created prior its configuration bean and the required connection pools.
If this is problematic for you, please let us know by voting for BTM-4.

Step 4: Configure Spring PlatformTransactionManager

Next, you need to create a Spring PlatformTransactionManager. There are many of them but the one we are interested in is the JtaTransactionManager. This is required as Spring internally uses PlatformTransactionManager for all transactional work.


This is really all you need to get JTA support with BTM inside Spring. You could directly make use of the JtaTransactionManager bean in your code but there are more elegant solutions: using Sping's AOP support to get declarative transaction management.

Step 5: Configure declarative transaction management

This can easily be achieved thanks to Spring's TransactionProxyFactoryBean.