微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Spring Data CrudRepository和Transactions

我正在尝试在CrudRepository接口上实现事务.我是初学者,我目前的问题是,当收到来自不同客户的大量请求时,我有时会得到重复.
为了避免这种情况,我想使用sql Transactions及其在Spring中的实现,但我无法使其正常工作.

以下是我尝试过的方法

@Repository
@EnableTransactionManagement
@Transactional
public interface ApplicationPackageDao extends CrudRepository

但它似乎不起作用.
我试图在我正在调用的Java方法中添加@Transactionnal注释,但我也无法使其工作.

我如何处理CrudRepository上的事务?
或者我完全使用了错误的东西?

最佳答案
我的建议是什么:

使用@Configuration批注检查上下文和配置类.从documentation

The @EnableTransactionManagement annotation provides equivalent
support if you are using Java based configuration. Simply add the
annotation to a @Configuration class

@EnableTransactionManagement and only looks
for @Transactional on beans in the same application context they are
defined in

然后,即使在方法中,您也可以在服务中使用@Transactional

希望能帮助到你

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐