开发者社区 问答 正文

spring事务配置的一个问题

applicationContext.xml中的关于事务的配置如下:

<tx:advice id="txAdvice" transaction-manager="transactionManager"> 
   <tx:attributes> 
        <tx:method name="delete*" rollback-for="Exception"/> 
        <tx:method name="save*" rollback-for="Exception"/> 
        <tx:method name="update*" rollback-for="Exception"/> 
        <tx:method name="*" read-only="true" rollback-for="Exception"/> 
   </tx:attributes> 
</tx:advice>
 
 
<aop:config> 
   <aop:pointcut id="serviceOperation"
         expression="execution(* *..service*..*(..))"/> 
   <aop:advisor pointcut-ref="serviceOperation"
          advice-ref="txAdvice"/> 
</aop:config>

通过切面、通知的配置,就为所有的service包下的delete/save/update开头的方法添加上了一致性事务,对其他方法添加上了只读事务。

 但是我在非delete/save/update开头的方法中却仍然能执行数据更新,那么这个只读事务有何用处?

展开
收起
a123456678 2016-03-16 10:03:40 1975 分享 版权
1 条回答
写回答
取消 提交回答
  • 因为在项目启始前就定义好了,非save/delete/update开头的方法不进行这种数据持久化操作,如果有其他非这3个开头的也可以进行数据库更新的方法,那么在声明事务时也要给它加上事务控制。

    2019-07-17 19:03:26
    赞同 展开评论
问答分类:
问答地址: