我们在Kotlin和springboot的项目作为框架。在我们的服务类中,我们有一堆代码,其中在标记为http
的方法中很少有@Transactional
调用。
我需要将http调用移到事务之外,因为这会造成性能问题。
代码如下所示:
@Transactional
Method1() {
“HTTP Call”
Saving to DB
“Call to another service B()”
}
在这个service B
中,我们调用一个Method2()
Method2() {
Bunch of operations and then it further Saves few objects to DB.
}
因此,基本上,@Transactional
也负责所有嵌套的DB操作。
对此,有什么建议吗?为实现这一目标,可以采用哪些不同的策略?
提前谢谢!
发布于 2020-02-27 02:48:15
所以我终于解决了这个问题。我不得不将我的方法从使用声明式事务管理改为编程方法。
Method1() {
“HTTP Call”
TransactionTemplate.execute() { // used this for the transaction management.
Saving to DB
}
“Call to another service B()”
}
然后在B服役
Method2() {
“Another http call”
TransactionTemplate.executewithoutResult(){ // used TransactionTemplate.executewithoutResult because this time I did not want the transaction to return me the result.
Saving to DB
}
}
https://stackoverflow.com/questions/60374535
复制相似问题