您现在的位置是: 首页 > 后端开发 > 编程开发
idea 提示 @Transactional self-invocation (in effect, a method within the target object calling another method of the target object) does not lead to an actual transaction at runtime 问题原因
2023-03-30 【后端开发】
简介
idea提示
@Transactional self-invocation (in effect, a method within the target object calling another method of the target object) does not lead to an actual transaction at runtime
这个警告意味着在方法内部使用了@Transactional
注解的情况下,方法自身调用了同一个类中的其他方法,而这个自调用实际上并不会启用Spring的事务管理。
这是因为Spring的事务是通过AOP动态代理实现的,也就是说,只有通过代理对象调用@Transactional
注解的方法时,事务才会生效。当一个方法在自身内部直接调用同一个类中的另一个方法时,Spring的事务管理是不会被触发的,因为这个调用并不是通过代理对象来实现的。
为了避免这个问题,可以将调用的方法抽取出来,单独定义一个接口,然后在类中注入接口实例,通过接口实例调用方法,这样Spring的事务管理就能生效了。或者使用AOP的方式,强制在同一个类中调用的方法也通过代理对象来实现,从而触发Spring的事务管理。
很赞哦! (0)
相关文章
- DataGrip 防止全表更新或删除限制
- idea 提示 @Transactional self-invocation (in effect, a method within the target object calling another method of the target object) does not lead to an actual transaction at runtime 问题原因
- IntelliJ IDEA 2023.1 发布,新UI 改进
- The bean 'xxxx.FeignClient' could not be registered. A bean with that name has already been defined and overriding is disabled. 问题原因
- Syntax Error: `asyncRouterMap` has already been exported. Exported identifiers must be unique. 错误原因
- MySQL 备份操作
- 控制台出现 was not registered for synchronization because DataSource is not transactional 是什么问题
- curl Empty reply from server 原因及解决方案
- Java BigDecimal 加减乘除计算示例
- docker容器里面没有vim解决方案
点击排行
- DataGrip 防止全表更新或删除限制
- idea 提示 @Transactional self-invocation (in effect, a method within the target object calling another method of the target object) does not lead to an actual transaction at runtime 问题原因
- IntelliJ IDEA 2023.1 发布,新UI 改进
- The bean 'xxxx.FeignClient' could not be registered. A bean with that name has already been defined and overriding is disabled. 问题原因
- Syntax Error: `asyncRouterMap` has already been exported. Exported identifiers must be unique. 错误原因
- MySQL 备份操作
- 控制台出现 was not registered for synchronization because DataSource is not transactional 是什么问题
- curl Empty reply from server 原因及解决方案
- Java BigDecimal 加减乘除计算示例
- docker容器里面没有vim解决方案
猜你喜欢
- DataGrip 防止全表更新或删除限制
- idea 提示 @Transactional self-invocation (in effect, a method within the target object calling another method of the target object) does not lead to an actual transaction at runtime 问题原因
- IntelliJ IDEA 2023.1 发布,新UI 改进
- The bean 'xxxx.FeignClient' could not be registered. A bean with that name has already been defined and overriding is disabled. 问题原因
- Syntax Error: `asyncRouterMap` has already been exported. Exported identifiers must be unique. 错误原因
- MySQL 备份操作
- 控制台出现 was not registered for synchronization because DataSource is not transactional 是什么问题
- curl Empty reply from server 原因及解决方案
- Java BigDecimal 加减乘除计算示例
- docker容器里面没有vim解决方案