在Spring MVC Service中如果需要重新启用一个事务需要配置Propagation.REQUIRES_NEW,这时,应当保证内外层两个方法不能再同一个类中。
public class ServiceA{
@Transactional(readOnly = false)
public void methodA(){
// do something
ServiceB.methodB();
// do something
}
}
public class ServiceB{
@Transactional(readOnly = false,propagation = Propagation.REQUIRES_NEW)
public void methodB(){
// do something
}
}
如果方法B执行成功,在方法A执行失败回滚后,方法B并不会回滚。