在以前的一篇详细介绍 Atomikos+spring实现JTA 的文章中是利用声明式事务配置,以共享同一个代理bean的方法实现事务配置,本文介绍下利用tx标签配置拦截器的方式实现事务配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
<!-- TransactionManager http://www.micmiu.com --> <!-- Construct Atomikos UserTransactionManager, needed to configure Spring --> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <!-- when close is called, should we force transactions to terminate or not? --> <property name="forceShutdown"> <value>true</value> </property> </bean> <!-- Also use Atomikos UserTransactionImp, needed to configure Spring --> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout"> <value>300</value> </property> </bean> <!-- Configure the Spring framework to use JTA transactions from Atomikos --> <bean id="springJTATransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager"> <ref bean="atomikosTransactionManager" /> </property> <property name="userTransaction"> <ref bean="atomikosUserTransaction" /> </property> </bean> <tx:annotation-driven transaction-manager="springJTATransactionManager" proxy-target-class="true" /> <tx:advice id="txAdvice" transaction-manager="springJTATransactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="transfer*" propagation="REQUIRED" rollback-for="Exception" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="serviceOperation" expression="execution(* com.micmiu.jta.demo.service.UserAccountService.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" /> </aop:config> <!-- Configure DAO http://www.micmiu.com --> <bean id="userInfoDao" class="com.micmiu.jta.demo.dao.UserInfoDaoImpl"> <property name="sessionFactory" ref="sessionFactory1" /> </bean> <bean id="bankAccountDao" class="com.micmiu.jta.demo.dao.BankAccountDaoImpl"> <property name="sessionFactory" ref="sessionFactory2" /> </bean> <bean id="userAccountService" class="com.micmiu.jta.demo.service.UserAccountServiceImpl"> <property name="userInfoDao" ref="userInfoDao" /> <property name="bankAccountDao" ref="bankAccountDao" /> </bean> |
本文介绍到此结束@Michael Sun.
原创文章,转载请注明: 转载自micmiu – 软件开发+生活点滴[ http://www.micmiu.com/ ]
你好,我按照你的方法配置了,但是怎么还会出现No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)这个错误啊??难道是我理解错了吗,按照这个配置不是应该成功搭建JTA的事务环境吗??
ref=”sessionFactory1″
ref=”sessionFactory2″
在哪里定义了?!
希望能认真看文章,文中应该有提到 前一篇介绍jta相关的文章,是在它的基础上 修改的,sessionFactory1 sessionFactory2的定义应该参考前一篇