开发者社区 问答 正文

Spring的事务传播属性propagation的默认值

propagation的默认值是REQUIRED么,spring3.0

我都是用的注解来处理事务的

@Transactional(propagation=Propagation.REQUIRED) 和 @Transactional是一样么?

请高手指点

展开
收起
a123456678 2016-03-12 17:58:36 5637 分享 版权
1 条回答
写回答
取消 提交回答
  • ServiceA {
    /**

    • 事务属性配置为 PROPAGATION_REQUIRED
      */

    void methodA() {
    ServiceB.methodB();
    }
    }

    ServiceB {
    /**

    • 事务属性配置为 PROPAGATION_REQUIRED
      */

    void methodB() {
    }

    }

    PROPAGATION_REQUIRED
    加入当前正要执行的事务不在另外一个事务里,那么就起一个新的事务
    比如说,ServiceB.methodB的事务级别定义为PROPAGATION_REQUIRED, 那么由于执行ServiceA.methodA的时候,
    ServiceA.methodA已经起了事务,这时调用ServiceB.methodB,ServiceB.methodB看到自己已经运行在ServiceA.methodA
    的事务内部,就不再起新的事务。而假如ServiceA.methodA运行的时候发现自己没有在事务中,他就会为自己分配一个事务。
    这样,在ServiceA.methodA或者在ServiceB.methodB内的任何地方出现异常,事务都会被回滚。即使ServiceB.methodB的事务已经被提交,但是ServiceA.methodA在接下来fail要回滚,ServiceB.methodB也要回滚
    /**

    • 如果ServiceB.methodB出现异常,会影响到ServiceA.methodA的提交么?
      */
    2019-07-17 19:01:19
    赞同 展开评论