liveBook · Manning

Execution order

As explained in Spring Start Here, Second Edition

Execution order is the sequence in which multiple aspects run when they intercept the same method.

When multiple aspects intercept one method, they form an execution chain: each aspect can delegate to the next. Their order matters because a security aspect that stops delegation may prevent a logging aspect from running. section 6.3

Security and logging

For a comment-publishing method, @Order(1) on SecurityAspect and @Order(2) on LoggingAspect put security first. Reversing their order lets logging run even when security stops the call. section 6.3

Figure 6.14 The aspect execution order matters. Depending on your app’s requirements, you need to choose a specific order for the aspects to execute. In this scenario, the LoggingAspect cannot log all the method executions if the SecurityAspect executes first.

Compare the chains to see why the chosen order determines whether logging can capture calls blocked by security. section 6.3

How Spring Start Here, Second Edition covers it

How deep it goes
Explains delegation through an execution chain and demonstrates @Order with aspect implementations and console output.
Examples
Uses security and logging aspects around a comment-publishing method to illustrate order-dependent behavior.
What you can do after
Configure aspect precedence with @Order to control which aspect intercepts a method first.
How it connects
Connects aspect ordering to method interception, security checks, and logging.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.