首先要下载jotm http://www.objectweb.org/jotm/download/
将jotm的lib copy到你的lib目录中
创建一个carol.properties文件,内容如下
# lmi stands for Local Method Invocation (it's a "fake" RMI)
carol.protocols=lmi
# do not use CAROL JNDI wrapper
carol.start.jndi=false
# do not start a name server
carol.start.ns=false
修改spring的配置文件如下:
<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
<bean id="innerDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource" destroy-method="shutdown">
<property name="transactionManager"><ref local="jotm"/></property>
<property name="driverName"><value>oracle.jdbc.driver.OracleDriver</value></property>
<property name="url"><value>jdbc:oracle:thin:@192.168.122.16:1521:tol</value></property>
</bean>
<bean id="dataSource" class="org.enhydra.jdbc.pool.StandardXAPoolDataSource" destroy-method="shutdown">
<property name="dataSource"><ref local="innerDataSource"/></property>
<property name="transactionManager"><ref local="jotm"/></property>
<property name="maxSize"><value>10</value></property>
<property name="user"><value>newclass</value></property>
<property name="password"><value>newclass</value></property>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="userTransaction"><ref local="jotm"/></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>hibernate/test.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="show_sql">true</prop>
<prop key="hibernate.dialect">net.sf.hibernate.dialect.OracleDialect</prop>
</props>
</property>
<property name="dataSource">
<ref local="dataSource"/>
</property>
</bean>
<bean id="transactionTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
<property name="proxyTargetClass"><value>true</value></property>
</bean>
<bean id="testDao" class="com.tol24.spring.test.jotm.TestDao">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>