Spring order annotations

I have a method with two annotations

@One @Two public Object foo() { ... } 

I have two aspects that use these annotations

 @Around("@annotation(One)") public Object doOne(final ProceedingJoinPoint joinPoint) throws Throwable { ... } 

and

 @Around("@annotation(Two)") public Object doTwo(final ProceedingJoinPoint joinPoint) throws Throwable { ... } 

But is the order in which these tips are performed vaguely?

+7
source share
4 answers

The order is undefined. If you need a specific order, use the @Order annotation.

See also:

+6
source

6.2.4.7. Counseling

What happens when a few tips everyone wants to work on the same connection point? Spring AOP follows the same priority rules as AspectJ to determine the order in which recommendations are followed. The highest priority advice starts first "on the way to" (so two pieces are given before the advice, the first with the highest priority is launched first). "To exit the junction point, the last seniority council works last (so two pieces are given after the consultation, the second will be performed with the highest priority).

When two pieces of advice, defined in different aspects, should be executed at the same join point, unless you specify otherwise the order of execution is undefined. You can control the execution order by specifying priority. This is done in the usual way in Spring by implementing the org.springframework.core.Ordered interface in a class or annotating it with an order annotation. Given two aspects, an aspect returning a lower value from Ordered.getValue () (or the value of the annotation) takes precedence.

When two pieces of advice, defined in the same aspect, must be executed at the same join point, the order is undefined (since there is no way to get order declarations via reflection for javac-compiled classes). Consider breaking down such consultation methods into one consultation method for one connection point in each class of classes or refactoring tips for individual aspect classes - which can be ordered at the aspect level.

http://static.springsource.org/spring/docs/2.0.x/reference/aop.html

+3
source

The order is undefined unless explicitly specified (e.g. using @Order )

+1
source
  • On the way to the junction, the advice with the lowest order value is first executed.

  • When leaving the connection point, tips with the highest order value are first executed.

  • When two boards defined in the same aspect, both must be executed at the same junction point, the order is undefined. Considers folding such advice methods into one consultation method per connection point in each class of classes or refactoring advice on individual aspect classes - which can be ordered at the aspect level.
0
source

All Articles