Search code examples
springspring-bootspring-aopspring-transactions

Control Execution Order of AOP and @Transactional


I am using spring boot 2.0.8 in a web application. I have methods in a Controller annotated with @Transactional. I also have an AOP @Around for the same method. In my testing I observe the AOP advise called inside the transaction (before my transaction revision coordinator gets called).

How can I change the order with the AOP advise executed before and after the transaction? From previous postings, it appears that @Order can be used but I am not seeing any differences.


Solution

  • Does it help if you set @EnableTransactionManagement(order = Ordered.HIGHEST_PRECEDENCE)? Or maybe the logic is somehow reverse and you need to set lowest precedence, I did not try. But lowest precedence should be the default already.

    See also these answers:

    See also these bits of Spring Javadoc: