Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

How to use BTM as the transaction manager in Tomcat 5.5.x

These instructions have been verified against BTM 1.1.

Contents

Step 1: Copy the BTM jars

Copy the following jars from the BTM distribution to the Tomcat common/lib/ directory:

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

Step 2: Configure BTM as the transaction manager

Windows: Create a file named setenv.bat with the following commands under Tomcat's bin/ directory:

Unix: Create a file named setenv.sh with the following commands under Tomcat's bin/ directory:

Now create a file named btm-config.properties with the following properties under Tomcat's conf/ directory:

Finally, create an empty file named resources.properties under Tomcat's conf/ directory.

Step 3: Configure datasources that are transaction aware

You have to put your datasources configurations in Tomcat's conf/resources.properties file. Here's an example of using BTM with a DataSource that implements javax.sql.XADataSource:

This will create a bitronix.tm.resource.jdbc.PoolingDataSource that implements javax.sql.DataSource and interacts with the javax.sql.XADataSource provided in this instance by Derby.

If your database vendor does not provide an XADataSource, you can use BTM's bitronix.tm.resource.jdbc.lrc.LrcXADataSource as the XADataSource to allow your database connections to be controlled by the transaction manager:

Again, we've used Derby as an example, but as the LrcXADataSource uses only the class name and url of a java.sql.Driver, you can use it with any database providing a JDBC driver.

Step 4: Configure transaction manager and datasources initialization in your META-INF/context.xml

In the web application where you want one or more datasource to be used, you have to create a META-INF/context.xml file.

The <Resource> tags will bind a bitronix.tm.resource.ResourceObjectFactory object each, passing it a javax.naming.Reference containing a javax.naming.StringRefAddr containing the datasource's uniqueName as addrType.

Tomcat specific

Icon

This mechanism is internal to Tomcat. You do not have to worry about how it works, the bitronix.tm.resource.ResourceObjectFactory class will handle those details.

The bitronix.tm.resource.ResourceObjectFactory class will return the datasource previously configured in in Tomcat's conf/resources.properties with the specified uniqueName when it is fetched from JNDI.

The <Transaction> tag will just bind the transaction manager at the standard JNDI location java:comp/UserTransaction.

Step 5: Configure datasources references in your web.xml

Before your code can access configured datasources via JNDI ENC URLs, you need to declare resource references in your web.xml:

Now you can perform JNDI lookups on those URLs to access the configured datasources:

  • No labels