通过this.xxx()方法调用导致声明式事务失效的问题
/**
* 手动匹配出入金
*/
@Transactional(rollbackFor = [Exception::class])
override fun manualMatch(request: ManualMatchReq) {
// 具体实现类
}
需要使用Spring管理的Bean来调用就能避免这个问题
/**
* 出入金-自动匹配
*/
override fun autoMatch() {
// 代付场景自动匹配(matchFlag是还未匹配的数据)
val autoMatchByRedemption = baseMapper.autoMatchByRedemption()
// 代收场景自动匹配(matchFlag是还未匹配的数据)
val autoMatchByCollect = baseMapper.autoMatchByCollect()
// 通过申请编码来区分每一次匹配记录
val redemptionMapByApplyCode = autoMatchByRedemption.groupBy { it.applyCode!! }
val collectMapByApplyCode = autoMatchByCollect.groupBy { it.applyCode!! }
// 每次记录生成对应的code
val code = UUID.getInstance().getUUIDWithPrefix(TableCodePrefixEnum.ES_FUND_BASIC.prefix)
// this.manualMatch() 子调用的时候,该方法会导致事务失效
// 使用Spring管理的Bean来调用,避免通过 "this." 的方式导致声明式事务失效
val itService = SpringUtil.getBean(this::class.java)
itService.manualMatch()
}