在接口规范或实现中

在接口规范或实现中

本文介绍了在哪里放@Transactional?在接口规范或实现中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

放置 @Transactional 注释时,最佳做法是什么?我应该注释接口方法还是实现?

What is considered the best practice in placing the @Transactional annotation? Should I annotate the interface method or the implementation?

推荐答案

好问题。我总是把它放在实施中。也许是因为它是一个实现细节,而不是一个抽象。

Good question. I've always put it in the implementation. Perhaps because it is an implementation detail, rather than an abstraction.

您可能希望不同的实现具有不同的交易行为。

You may want different implementations to have different transactional behaviours.

El Guapo指出,除此之外,与代理策略相关的接口可能会产生更多问题。

El Guapo noted that, in addition to that, there are more issues that can arise from putting on on the interface, related to the proxying strategy.

这篇关于在哪里放@Transactional?在接口规范或实现中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 23:25