我不想回滚在method3.i中发生的数据库更新。我尝试了下面的方法来做它。但它不工作,我错了? 请纠正我。
import org.springframework.transaction.annotation.Transactional;
@service
class1{
@Autowired
Class2 class2 ;
@Transactional(propagation = Propagation.REQUIRED)
method1(){
//do some work
//some check, on the basis of it which may throw exception.
MyResponseObject obj = flagclass.method2() ;
//do some work on the basis of obj,
//some condition on basis it may throw Exception.
}
}
@Service
class2{
public MyResponseObject method2(){
MyResponseObject obj ;
//do some work
if(condition) {
method3()
throw new Exception();
}
return obj ;
}
@Transactional(propagation = Propagation.REQUIRES_NEW)
method3(){
//do some update in db.
}
}
答案 0 :(得分:0)
我会创建注释:说@NoRollbackTransactional
@Transactional(noRollbackFor = RuntimeException.class)
public @interface NoRollbackTransactional {
}
并使用我不想回滚的方法。
您可能还需要关闭globalRollbackOnParticipationFailure。
<property name="globalRollbackOnParticipationFailure" value="false" />
还要完成此question