【发布时间】:2013-12-16 19:57:49
【问题描述】:
在我的应用程序中事务回滚之前运行某些代码时出现问题。我想要的是在发生异常时进行回滚,但我还想在表中存储一些有关该异常发生时应用程序状态的信息,包括任何错误或堆栈跟踪。
这是我的代码:
public void performAction(String approverId, Document document, String action) {
try {
LOG.info(String.format("routing document %s %s %s", approverId, document.getDocumentId(), action));
getDocumentService().route(approverId, document, action);
} catch (Exception e) {
LOG.error(String.format("error routing document %s %s %s", approverId, document.getDocumentId(), action));
LOG.error(e, e);
saveException(document, action, e); //this is what I want
}
}
saveException() 方法只是创建一个对象并将其保存到一个表中。
现在根据 Spring 文档about transactions,默认情况下会发生此回滚,其中异常是运行时异常,并且我已确认回滚工作正常,但不知何故不允许我的代码运行并保存我需要的信息或滚动那个也回来了(?)。
感谢您对解决方案的任何帮助或提示。
【问题讨论】:
标签: java spring transactions spring-transactions