目前JAVA的微服务项目基本都是SSM结构(即:springCloud +springMVC+Mybatis),而其中Mybatis事务的管理也是交由spring来管理,大部份都是使用声明式事务(@Transactional)来进行事务一致性的管理,然后在实际日常开发过程中,发现很多开发同学都用错了spring声明式事务(@Transactional)或者说使用非常不规范,导致出现各种事务问题。我(梦在旅途)今天周日休息,花了几个小时把目前我已知的开发常犯的几个错误都列举出来并逐一分析根本原因同时针对原因给出解决方案及示例,希望能帮助到广大JAVA开发者。 1. 事务不生效 问题现象:明明有事务注解,在事务方法内部有抛错,但事务却没有回滚,该执行的SQL都执行了。示例代码如下:(doInsert方法是有事务注解的) /** * @author zuowenjun * @see wwww.zuowenjun.cn */ @Service public class DemoUserService { //... ...
Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Get in touch with Return Demo
Contact Return Demo, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack