本文介绍了可以在@Transactional上应用@Order吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用@Transactional和另一个自定义注释@Custom注释的方法.此自定义批注环绕在建议周围.操作顺序如下:

I have a method which is annotated with @Transactional and another custom annotation @Custom. This custom annotation is wrapped around an advice. The sequence of operation is like below:

1.Transactional method gets called
2.Sees @Transactional and @Custom
3.As @Custom is intercepted by around advice, it first executes code before invocation of method
4.invocationContext.proceed()
5.Transaction gets created
6.Actual method runs
7.Back to around advice and executes code after method invocation

我想在调用建议之前创建交易.如下所示:

I want to create the transaction before the advice is called. Like below:

1.Transactional method gets called
2.Sees @Transactional and @Custom
3.Transaction gets created (propagate this transaction to @Custom)
4.As @Custom is intercepted by around advice, it first executes code before invocation of method
5.invocationContext.proceed()
6.Actual method runs
7.Back to around advice and executes code after method invocation

因此建议和方法都在同一笔交易中

So that both advice and method are in same transaction

我们可以在@Transactional上使用@Order,所以首先创建我的事务,然后执行建议吗?

Can we use @Order on @Transactional, so taht first my transacion is created and then the advice executed?

推荐答案

是的,在@Configuration类中使用:

@EnableTransactionManagement(order = Ordered.HIGHEST_PRECEDENCE)

或您需要的任何订单

这篇关于可以在@Transactional上应用@Order吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 06:53