Tomcat6上配置BTM
1)去http://docs.codehaus.org/display/BTM/Home上下载BTMzip包。
2)解压缩包,并将如下几个jar包拷贝tomcat6的lib下:btm-2.1.1.jar,btm-tomcat55-lifecycle-2.1.1.jar,geronimo-jta_1.1_spec-1.1.1.jar,slf4j-api-1.6.1.jar,slf4j-jdk14-1.6.1.jar。
3)拷贝对应数据的jdbc驱动包到tomcat6的lib下,则这边采用oracle11g作为后端测试的数据库,所以拷贝oracle jdk6.0 jdbc包ojdbc6.jar到lib下。
4)进入tomcat6的bin目录下,编辑startup.bat,在
set "EXECUTABLE=%CATALINA_HOME%\bin\catalina.bat"下增加一行
set "CATALINA_OPTS=-Dbtm.root=%CATALINA_HOME% -Dbitronix.tm.configuration=%CATALINA_HOME%\conf\btm-config.properties"后,进行保存。
bitronix.tm.serverId=spring-btmbitronix.tm.journal.disk.logPart1Filename=${btm.root}/work/btm1.tlogbitronix.tm.journal.disk.logPart2Filename=${btm.root}/work/btm2.tlogbitronix.tm.resource.configuration=${btm.root}/conf/resources.properties;
resource.ds1.className=oracle.jdbc.xa.client.OracleXADataSourceresource.ds1.uniqueName=jdbc/oracleresource.ds1.minPoolSize=0resource.ds1.maxPoolSize=5resource.ds1.allowLocalTransactions=true#resource.ds1.driverProperties.driverClassName=oracle.jdbc.driver.OracleDriverresource.ds1.driverProperties.URL=jdbc:oracle:thin:@localhost:1521:orclresource.ds1.driverProperties.user=scottresource.ds1.driverProperties.password=Pass1234。绑定的JNDI名称为:java:comp/env/jdbc/oracle。
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />下增加一行:
<Listener className="bitronix.tm.integration.tomcat55.BTMLifecycleListener" />用于监控BTM的生命周期(在tomcat启动或者关闭时);在同一目录下,编辑context.xml文件,在
<WatchedResource>WEB-INF/web.xml</WatchedResource>下增加一行:
<Transaction factory="bitronix.tm.BitronixUserTransactionObjectFactory" />配置UserTransaction,对应的jndi名称为:java:comp/UserTransaction。在增加一行对上面配置的数据源的引用:
<Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource" factory="bitronix.tm.resource.ResourceObjectFactory" uniqueName="jdbc/oracle" />