Setting the execution order of the aspects

When using several aspect classes, it can be necessary to set the order in which the aspects are executed. In this recipe, we will use two aspect classes with before advices targeting controller methods.

Getting ready

We will use the configuration from the Creating a Spring AOP aspect class recipe.

We will use these two aspect classes containing an advice, which logs some text when it's executed:

@Component @Aspect public class Aspect1 { @Before("execution(* com.spring_cookbook.controllers.*.*(..))") public void advice1() { System.out.println("advice1"); } } @Component @Aspect public class Aspect2 { @Before("execution(* com.spring_cookbook.controllers.*.*(..))") public void advice2() { System.out.println("advice2"); ...

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.