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>

 

posted on 2017-01-18 14:34  玄同太子  阅读(2042)  评论(0编辑  收藏  举报