Spring Boot 中的 @EnableTransactionManagement [英] @EnableTransactionManagement in Spring Boot

查看:40
本文介绍了Spring Boot 中的 @EnableTransactionManagement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring Boot 需要 @EnableTransactionManagement 吗?我做了一些研究.有些人说你不需要它,因为 Spring Boot 已经启用了它,其他人说你必须明确使用它.那么怎么样?

Is @EnableTransactionManagement required in Spring Boot? I did some research. Some folks say you don't need it, as Spring Boot has it already enabled, others say you do have to use it explicitly. So how is it?

推荐答案

可能您也在使用 Spring Data.默认情况下,即使没有 @EnableTransactionManagement,对 Spring Data 存储库的调用也被事务包围.如果 Spring Data 找到一个现有的事务,则现有的事务将被重用,否则会创建一个新的事务.

Probably you're also using Spring Data. Calls on Spring Data repositories are by default surrounded by a transaction, even without @EnableTransactionManagement. If Spring Data finds an existing transaction, the existing transaction will be re-used, otherwise a new transaction is created.

@Transactional 注释仅在您激活 @EnableTransactionManagement(或以其他方式配置事务处理)时才进行评估.

@Transactional annotations within your own code, however, are only evaluated when you have @EnableTransactionManagement activated (or configured transaction handling some other way).

您可以通过将以下属性添加到您的 application.properties 来轻松跟踪事务行为:

You can easily trace transaction behavior by adding the following property to your application.properties:

logging.level.org.springframework.transaction.interceptor=TRACE

(参见在日志中显示 Spring 事务)

这篇关于Spring Boot 中的 @EnableTransactionManagement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆