【发布时间】:2019-03-17 21:17:18
【问题描述】:
我正在开发一个 Spring-Boot 应用程序并使用 Spring Boot 1.5.9 版。
我有一个包含一组数据库插入的付款转移方法,我想将其设置为带有锁定的事务性以避免双重支出。所以我需要将隔离级别设置为可序列化。 这就是我所做的:
@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 的 allowCustomIsolationLevels 设置为 true。但相反,我应该使用 Java 注释和 @Bean 定义,但我不确定如何实现我的目标。
任何帮助将不胜感激!
【问题讨论】:
标签: java spring spring-boot