[英]Ensure methods called are within Spring @Transactional boundary
I'm using org.springframework.transaction.annotation.Transactional
and am calling methods that I only want to be able to be called from a method annotated with @Transactional
.我正在使用
org.springframework.transaction.annotation.Transactional
并且正在调用我只想能够从用@Transactional
注释的方法调用的方法。
For reasons I won't pollute this question with, the methods I want to call as part of the transaction should never be called out with the transaction boundary and I want to enforce this.出于我不会污染这个问题的原因,我想作为事务的一部分调用的方法不应该被事务边界调用,我想强制执行这一点。
Is there an annotation or similar I can use to ensure these methods are only able to be successfully called from a method annotated with @Transactional
?是否有注释或类似的我可以用来确保这些方法只能从用
@Transactional
注释的方法成功调用?
In a simplest case you can use Propagation.MANDATORY
(ie @Transactional(propagation=Propagation.MANDATORY)
) transactional propagation instead of default Propagation.REQUIRED
.在最简单的情况下,您可以使用
Propagation.MANDATORY
(即@Transactional(propagation=Propagation.MANDATORY)
)事务传播而不是默认的Propagation.REQUIRED
。
If you use programmatic transactions then you check TransactionStatus
getters - even if your propagation is REQUIRED
you can verify that TransactionStatus.isNewTransaction()
returns false.如果您使用程序化事务,那么您检查
TransactionStatus
getter - 即使您的传播是REQUIRED
您也可以验证TransactionStatus.isNewTransaction()
返回 false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.