【发布时间】:2021-05-03 19:47:25
【问题描述】:
我正在开发一个 Spring Boot 应用程序,该应用程序需要在引发错误时回滚所有数据库事务。例如,我正在与学生创建一个文件,当我给它一个未知的路径时,我有一个 FileNotFoundException 但数据库中的保存已提交。我被要求在每个技术错误上回滚已提交的事务。有什么帮助吗?
我的代码示例:
@Override
public boolean registerStudent(Student student){
//some code
student.setStatus("registred");
studentService.save(student);
createFile(student);
//return
}
private void createFile(Student student) throws IOException{
try {
//code to create file
} catch (IOException ex) {
//log the error
}
}
【问题讨论】:
标签: java spring oracle spring-boot spring-transactions