Atomikos+spring AOP方式实现JTA事务配置的示例

7 篇文章 0 订阅
7 篇文章 0 订阅

本文转自:http://www.micmiu.com/j2ee/jta/jta-atomikos-cfg-tx/


在以前的一篇详细介绍 Atomikos+spring实现JTA 的文章中是利用声明式事务配置,以共享同一个代理bean的方法实现事务配置,本文介绍下利用tx标签配置拦截器的方式实现事务配置:

1<!-- TransactionManager http://www.micmiu.com -->
2<!-- Construct Atomikos UserTransactionManager, needed to configure Spring -->
3<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
4    init-method="init" destroy-method="close">
5    <!-- when close is called, should we force transactions to terminate or
6        not? -->
7    <property name="forceShutdown">
8        <value>true</value>
9    </property>
10</bean>
11 
12<!-- Also use Atomikos UserTransactionImp, needed to configure Spring -->
13<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp">
14    <property name="transactionTimeout">
15        <value>300</value>
16    </property>
17</bean>
18 
19<!-- Configure the Spring framework to use JTA transactions from Atomikos -->
20<bean id="springJTATransactionManager"
21    class="org.springframework.transaction.jta.JtaTransactionManager">
22 
23    <property name="transactionManager">
24        <ref bean="atomikosTransactionManager" />
25    </property>
26    <property name="userTransaction">
27        <ref bean="atomikosUserTransaction" />
28    </property>
29</bean>
30 
31<tx:annotation-driven transaction-manager="springJTATransactionManager"
32    proxy-target-class="true" />
33 
34<tx:advice id="txAdvice" transaction-manager="springJTATransactionManager">
35    <tx:attributes>
36        <tx:method name="save*" propagation="REQUIRED" />
37        <tx:method name="update*" propagation="REQUIRED" />
38        <tx:method name="transfer*" propagation="REQUIRED"
39            rollback-for="Exception" />
40        <tx:method name="*" read-only="true" />
41    </tx:attributes>
42</tx:advice>
43<aop:config>
44    <aop:pointcut id="serviceOperation"
45        expression="execution(* com.micmiu.jta.demo.service.UserAccountService.*(..))" />
46    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
47</aop:config>
48 
49<!-- Configure DAO http://www.micmiu.com -->
50<bean id="userInfoDao" class="com.micmiu.jta.demo.dao.UserInfoDaoImpl">
51    <property name="sessionFactory" ref="sessionFactory1" />
52</bean>
53<bean id="bankAccountDao" class="com.micmiu.jta.demo.dao.BankAccountDaoImpl">
54    <property name="sessionFactory" ref="sessionFactory2" />
55</bean>
56 
57<bean id="userAccountService" class="com.micmiu.jta.demo.service.UserAccountServiceImpl">
58    <property name="userInfoDao" ref="userInfoDao" />
59    <property name="bankAccountDao" ref="bankAccountDao" />
60</bean>

本文介绍到此结束@Michael Sun.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值