@EnableTransactionManagement

Spring使用事务非常简单,首先使用注解 @EnableTransactionManagement 开启事务支持后(在启动类上面添加即可),然后在访问数据库的Service方法上添加注解 @Transactional 便可。

该注解相当于xml配置方式的 <tx:annotation-driven />

如果是springboot,可以直接在服务层类上添加注解@Transactional即可,Springboot会自动配置

 

posted @ 2020-10-09 11:24  JoelYe  阅读(2372)  评论(0编辑  收藏  举报