Java 使用SpringBoot处理事务隔离级别
我正在开发一个SpringBoot应用程序,使用SpringBoot1.5.9版 我有一个支付转账方法,其中包含一组DB插入,我希望通过锁定实现事务性,以避免重复支出。所以我需要将隔离级别设置为Serializable。 这就是我所做的:Java 使用SpringBoot处理事务隔离级别,java,spring,spring-boot,Java,Spring,Spring Boot,我正在开发一个SpringBoot应用程序,使用SpringBoot1.5.9版 我有一个支付转账方法,其中包含一组DB插入,我希望通过锁定实现事务性,以避免重复支出。所以我需要将隔离级别设置为Serializable。 这就是我所做的: @Transactional(isolation = Isolation.SERIALIZABLE) public void transfer() { ... } 问题是调用此方法时出现以下异常: { "timestamp": 15393578514
@Transactional(isolation = Isolation.SERIALIZABLE)
public void transfer() {
...
}
问题是调用此方法时出现以下异常:
{
"timestamp": 1539357851437,
"status": 500,
"error": "Internal Server Error",
"exception": "org.springframework.transaction.InvalidIsolationLevelException",
"message": "JtaTransactionManager does not support custom isolation levels by default - switch 'allowCustomIsolationLevels' to 'true'",
"path": "app/transfer"
}
一般来说,我是Spring新手,SpringBoot似乎没有一个XML配置,我可以覆盖它来为JtaTransactionManager bean将AllowCustomIsolationLevel设置为true。但是我应该使用Java注释和@Bean定义,我不知道如何实现我的目标
任何帮助都将受到感谢 如果您想使用XML文件进行配置,在具有
@SprintBootApplication
注释的主类中,只需添加以下内容:
@ImportResource(“classpath:/static/context/name of context file.xml”)
它将从根目录是项目中资源目录的路径导入XML文件
从我可以看出,您可能希望研究使用DataSourceTransactionManager或使用我提到的XML文件,因为根据该文档(与错误消息状态非常相似,但至少为您提供了设置选项)
JTA不支持自定义隔离级别
我知道我链接的页面很长,但如果您只需在页面上查找“自定义隔离”,它会将其缩小到三个选项,其中两个选项彼此相邻
希望这有帮助。那么
setAllowCustomIsolationLevel(true)
意味着Spring将通过Spring JTA而不是JTA支持自定义隔离级别?