liveBook · Manning

@Aspect annotation

As explained in Spring Start Here, Second Edition

The @Aspect annotation marks a class as defining aspect-oriented behavior for interception by an aspect framework.

@Aspect marks a class as defining aspect logic for Spring AOP. It does not register the class as a Spring bean: Spring must manage an instance, and aspect support must be enabled separately. section 6.5 section 6.2.1

Listing 6.6 Defining an aspect class
@Aspect
public class LoggingAspect {
  public void log() {
    // To implement later
  }
}

A minimal LoggingAspect shows the annotation on the class; the class still needs to be registered as a Spring bean. section 6.2.1

Logging around a service call

A LoggingAspect can use @Around advice to log before and after CommentService.publishComment(). The annotation identifies the aspect class; the advice and its pointcut specify what to intercept and when. section 6.2.1 section 6.5

How Spring Start Here, Second Edition covers it

How deep it goes
Defines the class marker and bean-registration requirement, then places it in a setup that also uses advice and pointcuts.
Examples
Uses a LoggingAspect to add before-and-after logging around CommentService.publishComment().
What you can do after
Build it from scratch by marking an aspect class, registering its bean, enabling aspect support, and adding advice.
How it connects
Connects to Spring AOP, Spring beans, advice, pointcuts, weaving, and @EnableAspectJAutoProxy.

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.