1、通过注解方式@Transactional
@Transactional(rollbackForClassName = { "Exception", "RuntimeException" }) public void save(PersonEntity entity) { personDao.save(entity); }
2、通过切片方式
<!-- 配置事务传播特性 --> <tx:advice id="advice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="get*" read-only="true" /> <tx:method name="*" rollback-for="Exception" /> </tx:attributes> </tx:advice> <!-- 配置参与事务的类 --> <aop:config> <aop:pointcut id="all" expression="execution(* com.zhi.service.*.*(..))" /> <aop:advisor pointcut-ref="all" advice-ref="advice" /> </aop:config>
原文:http://www.cnblogs.com/zhi-leaf/p/6296647.html