liveBook · Manning

AspectJ pointcut language

As explained in Spring Start Here, Second Edition

An AspectJ pointcut expression selects join points, such as method executions, where aspect advice applies.

A pointcut expression tells Spring which method calls an aspect should intercept. You provide it as the value of an advice annotation, such as @Around or @AfterReturning. section 6.2.1 section 6.2.4

Pointcuts can select methods by different criteria:

  • `execution(* com.example.services.*.*(..))` selects methods in the services package, regardless of return type, class, method name, or parameters. section 6.2.1
  • `@annotation(ToLog)` selects methods marked with `@ToLog`; a runtime-retained annotation lets the aspect intercept them. section 6.2.3

Expressions can be powerful and complex, but simple alternatives are often preferable. You need not learn the language by heart; consult documentation when needed. section 6.2.1

Figure 6.12 The steps for intercepted annotated methods. You need to create a custom annotation you want to use to annotate the methods your aspect needs to intercept. Then you use a different AspectJ pointcut expression to configure the aspect to intercept the methods annotated with the custom annotation you created.

See how a custom annotation and a pointcut expression work together to select methods for interception. section 6.2.3

How Spring Start Here, Second Edition covers it

How deep it goes
Defines pointcuts through package and annotation examples, while discouraging complex expressions rather than teaching their full grammar.
Examples
Uses a services-package execution pattern and a custom @ToLog annotation to select methods.
What it assumes
Starts with a simple Spring service and explains pointcuts without requiring AspectJ expertise.
What you can do after
Configure Spring advice to intercept service methods or methods marked with a custom annotation.
How it connects
Connects Spring AOP with aspects, advice annotations, and method executions.

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.