![](/img/trans.png)
[英]Understanding Spring transactions - What happens when a transactional method calls another transactional method?
[英]Spring @Transactional Service. What happens if it calls another @Transactional Service?
使用 Spring,我达到了以下场景。
我有一个必须是@Transactional
的服务,因为它调用了几个 DAO。 但它也会调用其他已经是@Transactional
的服务。
不知何故,我将调用嵌套的@Transactional
服务。
Spring 管理得好吗?
没有任何显式参数的@Transactional
使用propagation = REQUIRED
。 这表示:
使用@Transactional
注释的第二个服务(嵌套的)将在与第一个(外部)相同的事务中执行。 你不需要做任何事情。
在某些情况下,如果您想明确地将嵌套调用与外部调用分开,您可以使用propagation = REQUIRES_NEW
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.