- springboot 的事物是利用APO实现的,所以加了synchronized,是在事物内加了同步,所以需要在controller里面加synchronized就可以了
- 如果是在service里加方法
@Service
class TestSyncService{
@Transactional
public synchronized void a (){
//do something
}
public synchronized void b (){
b();
}
}
这样的话事物会不生效的,不会回滚
还有一个办法是 不要直接调用b, 要把自己的service 注入,
@Service
class TestSyncService{
@Autowired
private TestSyncService testSyncService
@Transactional
public synchronized void a (){
//do something
}
public synchronized void b (){
testSyncService.b();
}
}