Spring aop切面插入事物回滚



<!-- tx标签配置 事物-->
<tx:advice id="txadvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
        <tx:method name="modify*" propagation="REQUIRED" rollback-for="Exception" />
        <tx:method name="del*" propagation="REQUIRED" rollback-for="Exception"/>
        <tx:method name="*" propagation="REQUIRED" read-only="true"/>
    </tx:attributes>
</tx:advice>
<!--aop切面插入事物-->
<aop:config>
    <aop:pointcut id="daoMethod" expression="execution(* com.dao.*.*(..))"/>
    <aop:advisor pointcut-ref="daoMethod" advice-ref="txadvice"/>
</aop:config>
execution中的 第一个*代表返回值,第二*代表dao下子包,第三个*代表方法名,(..)代表方法参数。
如果执行的过程中发生异常,则会事物回滚。

原文地址:https://www.cnblogs.com/caixiaohua/p/6698358.html