spring-boot - 如何在自定义方面回滚事务
问题描述
这是我的代码
@Around("service()")
public Object serviceThreadLocalHandle(ProceedingJoinPoint joinPoint) throws Throwable{
// joinPoint is a service instance
Object proceed = joinPoint.proceed();
cache = ContractCache.LOCAL_CACHE.get();
// there i throw a exception but i can not rollback the transaction
if(true){
throw new RuntimeException();
}
return proceed;
}
那么如何在我的方面 Spring Boot 版本 1.5.8 RELEASE 上回滚事务?
解决方案
您可以在 @Transactional 注释中声明您希望在抛出 RuntimeException 时执行回滚:@Transactional(rollbackFor=RuntimeException.class)
推荐阅读
- javascript - 为什么 Bootstrap 5.0.1 中的下拉菜单和汉堡菜单无法在任何地方打开?
- java - 在联接表中添加新列
- javascript - 使用相同的键触发网站中的两个不同操作 - TamperMonkey - JavaScript
- php - Wordpress - GET 参数不适用于 NGINX
- docker - DockerCompose 操作不匹配
- javascript - JavaScript Discord Bot 没有响应
- wordpress - 有什么方法可以从 fb shop / catalogue 导出产品数据?
- reactjs - 如何在本机中动态导入图像?
- android - 如何为具有上下文、标题和消息的函数编写本地单元测试用例?
- python - 使用 Sqlalchemy 在多个外键上创建连接