spring 事务处理常规记录
2013-02-26 16:11
357 查看
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <tx:annotation-driven /> <aop:config > <aop:advisor pointcut="execution(* com.abc.ccb.service.*.*(..))" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="new*" propagation="REQUIRED"/> <tx:method name="edit*" propagation="REQUIRED"/> <tx:method name="del*" propagation="REQUIRED"/> <tx:method name="insert*" propagation="REQUIRED"/> <tx:method name="save*" propagation="REQUIRED"/> <tx:method name="*TX" propagation="REQUIRED" rollback-for="java.lang.Exception"/> <!-- <tx:method name="*" read-only="true" /> --> </tx:attributes> </tx:advice>
以上是 applicationContext.xml 配置 事务和AOP。 (ORM是 ibatis)
执行的控制范围在 com.abc.ccb.service 包里的任意方法 . 感谢 http://blog.csdn.net/kkdelta/article/details/7441829 这篇博客提供的参考.
过程中出现不回滚一个小问题.
在service 中的一个 *TX方法中 我对数据库操作语句进行的try catch 异常捕捉, 制造事务异常执行时,发现事务没回滚.
然后解决方法:将service中异常向外抛throws ,action 中捕获异常, 这时再操作事务机制可以回滚了.
同时也发现了这个也应该算是一个编码规范.记录.
相关文章推荐
- spring@Transactional注解事务不回滚不起作用无效的问题处理
- Spring-jdbc-事务处理详解及案例<五>
- 基于Eclipse Maven的Spring4/Spring-MVC/Hibernate4整合之十:Spring mvc & hibernate 事务处理(回滚)
- 20110223 学习记录:事务处理
- 基于spring多数据源动态调用及其事务处理
- Spring事务学习记录
- Hibernate整合进spring---使用自己的事务处理
- Spring事务异常回滚失败原因,在事务处理层捕获异常不抛出就不会回滚
- Spring 的声明式事务处理
- spring 事务处理
- spring入门之ssh中事务处理,数据库连接,spring配置文件
- Spring源代码解析(六):Spring声明式事务处理
- spring事务如何处理
- Spring整合JDBC及事务处理
- spring事务处理
- 揭开Spring事务处理
- Spring 的事务处理浅谈
- Spring 的事务处理
- 《Spring技术内幕》学习笔记14——Spring读取和处理事务配置
- Spring的事务处理机制