一、
<!-- 事务管理 通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <!-- 对insert,update,delete 开头的方法进行事务管理,只要有异常就回滚 --> <tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/> <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/> <tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/> <tx:method name="fileUpload" propagation="REQUIRED" rollback-for="java.lang.Throwable"/> <tx:method name="fileDownload" propagation="REQUIRED" rollback-for="java.lang.Throwable"/> <!-- select,count开头的方法,开启只读,提高数据库访问性能 --> <tx:method name="select*" read-only="true"/> <tx:method name="count*" read-only="true"/> <!-- 对其他方法 使用默认的事务管理 --> <tx:method name="*"/> </tx:attributes> </tx:advice> <!-- 事务 aop 配置 --> <aop:config> <aop:pointcut id="serviceMethods" expression="(execution(* org.szfzx.siss.**.service.**.**.*(..)))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"/> </aop:config> <!-- 配置使Spring采用CGLIB代理 --> <aop:aspectj-autoproxy proxy-target-class="true"/> <!-- 启用对事务注解的支持 --> <tx:annotation-driven transaction-manager="transactionManager"/>
二、
<!-- 事务 aop 配置 --> <aop:config> <aop:pointcut id="serviceMethods1" expression="execution(* org.szfzx.siss.**.service.**.**.update*(..))"/> <aop:pointcut id="serviceMethods2" expression="execution(* org.szfzx.siss.**.service.**.**.insert*(..))"/> <aop:pointcut id="serviceMethods3" expression="execution(* org.szfzx.siss.**.service.**.**.delete*(..))"/> <aop:pointcut id="serviceMethods4" expression="execution(* org.szfzx.siss.**.service.**.**.fileUpload(..))"/> <aop:pointcut id="serviceMethods5" expression="execution(* org.szfzx.siss.**.service.**.**.fileDownload(..))"/> <aop:advisor pointcut-ref="serviceMethods1" advice-ref="txAdvice"/> <aop:advisor pointcut-ref="serviceMethods2" advice-ref="txAdvice"/> <aop:advisor pointcut-ref="serviceMethods3" advice-ref="txAdvice"/> <aop:advisor pointcut-ref="serviceMethods4" advice-ref="txAdvice"/> <aop:advisor pointcut-ref="serviceMethods5" advice-ref="txAdvice"/> </aop:config> <!-- 事务管理 通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="*" rollback-for="java.lang.Exception" /> </tx:attributes> </tx:advice>