在相互调用时能够共享同一个事务,以保证事务生效
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.aop.framework.AopContext;
@Service
public class YourService {
public void methodA() {
// 事务将在此处生效
((YourService) AopContext.currentProxy()).methodB();
}
@Transactional
public void methodB() {
// 此处的事务将生效
// 你的具体业务逻辑
}
}