liveBook · Manning

Execution chain

As explained in Spring Start Here, Second Edition

An execution chain is an ordered sequence in which multiple aspects and the intercepted method delegate execution to one another.

An execution chain is the ordered path through which multiple aspects delegate a method call to one another and, eventually, to the intercepted method. Each aspect can also affect whether the call proceeds. section 6.3

Order matters when aspects have different effects:

  • If SecurityAspect runs first and declines to delegate, LoggingAspect never runs; it cannot log that call. section 6.3
  • Spring does not guarantee the default order. Use @Order on an aspect to set it; a smaller number runs earlier, while equal values leave the order undefined. section 6.3

A comment service call

For publishComment(), LoggingAspect can run before SecurityAspect, which delegates to the service method. Reversing their order can prevent logging 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 two possible orders and see why logging may miss calls when security runs first. section 6.3

How Spring Start Here, Second Edition covers it

How deep it goes
Explains delegation, order-dependent behavior, and @Order precedence, including undefined ties.
Examples
Uses LoggingAspect, SecurityAspect, and CommentService.publishComment() to show order-dependent logging.
What you can do after
Configure aspect precedence with @Order when execution order affects application behavior.
How it connects
Connects Spring AOP, aspects, and the @Order annotation.

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.