简体   繁体   English

如何为不同的方法使用不同的 spring 事务

[英]How to use different spring transactions for different methods

I am having a problem with the persistence of a method that is calling another methods to do persistence at my oracle db.我在我的 oracle 数据库中调用另一种方法来执行持久性的方法的持久性存在问题。

I will try to explain as better as i can to make more easy to you guys, I hope that you can help me.我会尽力解释得更好,让你们更容易,我希望你们能帮助我。

This is my scenario.这是我的场景。

I have a component, in which i am calling a method that looks like that:我有一个组件,我在其中调用一个看起来像这样的方法:

public void execute() throws Exception {
    service1.method1(); // @Transactional
    service2.method2(); // @Transactional(propagation = Propagation.REQUIRES_NEW)
    service3.method3(); // @Transactional(propagation = Propagation.REQUIRES_NEW)
}

The thing is that i need to persist every method separately in case that one of them gets an exception, the others could be persisted.问题是我需要分别保留每个方法,以防其中一个出现异常,其他方法可以保留。

Right now the problem i have is that i am having a deadlock and my code stills running until i stop my application, and the transactions never end.现在我遇到的问题是我遇到了死锁,我的代码仍在运行,直到我停止我的应用程序,并且事务永远不会结束。

I tried so many things, but i am trying without the needed knowledge to work with this spring transactions and i do not know what more i can try to do.我尝试了很多东西,但我在没有必要的知识的情况下尝试使用此 spring 事务,我不知道我还能尝试做什么。

Can you bring me some light on this dark hole where i am right now?你能为我现在所在的这个黑洞带来一些启示吗?

Really, thank you.真的很谢谢你。

Spring AOP same class method will not works. Spring AOP 相同的 class 方法将不起作用。 this.method1(); this.method1(); // @Transactional will not work. // @Transactional 将不起作用。

more explanation in this thread Same class invoke NOT effective in Spring AOP cglib此线程中的更多解释相同的 class 调用在 Spring AOP cglib 中无效

u can register different transactionManager, and ur services use its @Transactional(tx="xxx")你可以注册不同的事务管理器,你的服务使用它的@Transactional(tx="xxx")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App Engine数据存储交易的两种不同方法-使用哪种? - Two different methods for Google App Engine Datastore Transactions — which to use? 何时在 spring 中使用不同的请求方法 - When to use different request methods in spring 如何对泛型使用不同的方法 - How to use different methods with generics 对不同的测试方法使用不同的Spring测试上下文配置 - Use different Spring test context configuration for different test methods 无论如何,不​​同DAO中的Spring事务仍然无法工作? - Spring Transactions in different DAOs does not work anyway? Spring的具有不同transactionManagers的嵌套事务 - Spring's nested transactions with different transactionManagers spring中与不同事务管理器的嵌套事务 - Nested transactions with different transaction managers in spring 如何以不同的方法使用 arraylist 但方法在 class 内部 - How to use arraylist in different methods but the methods are inside of the class 如何在Controller Java Spring中使用不同的GET方法 - How to have to different GET methods in Controller Java Spring 如何在Spring中将具有相同前缀uri的映射重载到不同的方法? - How to overload mapping with same prefix uri to different methods in Spring?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM