@EnableTransactionManagement in Spring Boot

后端 未结 6 1775
你的背包
你的背包 2020-12-07 16:58

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 s

6条回答
  •  一整个雨季
    2020-12-07 17:09

    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 annotations within your own code, however, are only evaluated when you have @EnableTransactionManagement activated (or configured transaction handling some other way).

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

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

    (see Showing a Spring transaction in log)

提交回复
热议问题