本文介绍了@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