配置事务切面好处是你可以先提交到mybatis,后面可以从mybatis查库,后面的代码抛异常可以回滚整个方法的事务。但是注意的是这个方法结束后才会提交到数据库,也就是说mybatis修改数据库是在整个方法结束时才开始的,如果此时另一个线程在代码执行到修改数据库时去读数据库,读到的依然是未修改的老数据,这也是事务的一个缺点
<!-- 配置事务切面 -->
<aop:config>
<aop:pointcut id="serviceOperation" expression="
execution(* com.feature.controller..*.*(..))
|| execution(* com.feature.*.service..*.*(..))
" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
</aop:config>
<!-- 配置事务通知属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定义事务传播属性 -->
<tx:attributes>
<tx:method name="create" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="run" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="update*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="edit*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="save*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="add*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="new*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="remove*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="del*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="change*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="execute*" propagation="REQUIRED" rollback-for="Exception" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="load*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>