@Transactional(propagation = Propagation.REQUIRED)在春季? [英] @Transactional(propagation = Propagation.REQUIRED) in spring?

查看:727
本文介绍了@Transactional(propagation = Propagation.REQUIRED)在春季?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有以下代码:

@Component
public class A{ 

@Transactional(propagation = Propagation.REQUIRED)
public void a(){
    //logic
    b();
 //logic
}

@Transactional(propagation = Propagation.REQUIRED)
public void b(){
    //logic
} 
}

在此代码示例中有多少笔交易打开了Spring?

How many transactions open Spring in this code example?

推荐答案

没关系.从a()调用b()时,它将不会通过代理,因此不会考虑b()上的任何事务属性.

It doesn't matter. When calling b() from a() it won't be going through the proxy, so any transactional attributes on b() won't be considered.

如果通过代理(即在类外部)调用a()b(),示例代码将打开1个事务,并且尚无正在进行的事务.

The example code has 1 transaction open if a() or b() is called through the proxy (i.e. outside of the class) and there isn't a transaction in progress already.

这篇关于@Transactional(propagation = Propagation.REQUIRED)在春季?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆