can @Order be applied on @Transactional?

混江龙づ霸主 提交于 2019-12-10 17:24:19

问题


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

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


回答1:


Yes, in the @Configuration class use:

@EnableTransactionManagement(order = Ordered.HIGHEST_PRECEDENCE)

or whatever order you need




回答2:


You could try adding @transaction(propagation=required)on top of @custom annotation . It may hopefully work



来源:https://stackoverflow.com/questions/35460436/can-order-be-applied-on-transactional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!