Spring事务问题 - MyBatis

[已解决]was not registered for synchronization because synchronization is not active。

was not registered for synchronization because synchronization is not active
DEBUG org.mybatis.spring.SqlSessionUtils - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@62eb1dea] was not registered for synchronization because synchronization is not active
DEBUG org.mybatis.spring.SqlSessionUtils - Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3fc8edfb] from current transaction

两种情况:

配置问题,检查是否配置了事务:

@Transactional

调用方式:

如果将@Transactional放置类上,不会出现以下调用问题。

Service.java

@Service
public class Service {

   @Transactional
   public boolean save(Object o) {/**todo**/}

    public boolean update(Object o) {
		save(o);
    }
}

Controller.java

public class Controller {
	 
      @Autowired     
      Service s;
    
      public void  update(){
        		s.update();
       }
}

说明:事务不受Spring管理。

public class Controller {
	 
      @Autowired     
      Service s;
    
      public void  update(){
        	s.save();
       }
}

说明:事务受Spring管理。

原因,前者走this指针,后者走事务拦截处理逻辑。