我有一个用@Transactional和另一个自定义注释@Custom注释的方法。这个自定义注释包含在一个建议中。操作顺序如下:
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
我想在调用通知之前创建事务。如下所示:
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
因此建议和方法都在同一个交易中
我们可以在@Transactional上使用@Order,所以首先创建我的transacion然后执行建议吗?
答案 0 :(得分:4)
是的,在@Configuration
班级中使用:
@EnableTransactionManagement(order = Ordered.HIGHEST_PRECEDENCE)
或您需要的任何订单
答案 1 :(得分:0)
我想@EnableTransactionManagement(order = Ordered.HIGHEST_PRECEDENCE)
是全局配置。
如果只想在此方法{{1}上使用@Transactional
,而不是其他方法,则可以定义方法A()
来调用B()
。这样可以指出注释的顺序。
赞:
A()
答案 2 :(得分:-1)
您可以尝试在@custom注释之上添加@transaction(propagation = required)。它可能有希望工作