spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.27k stars 37.62k forks source link

Sort AspectJ annotated advice methods using `@Order` #32745

Closed Puppy4C closed 2 weeks ago

Puppy4C commented 2 weeks ago

This PR provides the ability to use @Order sorting for Advice Annotation.

Example:

@Aspect
public class MyAspect {

    @Order(1)
    @Before("execution(* org.example.AopObj.*(..))")
    public void method1() {
        System.out.println("Before method-1");
    }

    @Order(2)
    @Before("execution(* org.example.AopObj.*(..))")
    public void method2() {
        System.out.println("Before method-2");
    }

}

method1() will be executed before method2() because the sequence number of method1() is smaller.

snicoll commented 2 weeks ago

Thanks for the PR. This was declined in #29732 and #32570 already.