What is the difference between Advisor and Aspect in AOP?

Advisors seem to be an old "AOP lite" type of defining cross-cutting concerns from Spring 1.2 when Java 5 usage was still somewhat uncommon and thus @AspectJ syntax (via Java annotations) not used in Spring. The concept has still survived for lovers of schema-based AOP rather than annotation-based AOP or pure AspectJ syntax, see Spring documentation on advisors.

The concept of "advisors" comes from the AOP support defined in Spring and does not have a direct equivalent in AspectJ. An advisor is like a small self-contained aspect that has a single piece of advice. The advice itself is represented by a bean and must implement one of the advice interfaces described in Advice Types in Spring. Advisors can take advantage of AspectJ pointcut expressions.


Most aspects are a combination of advice that defines the aspect’s behavior and a pointcut defining where the aspect should be executed.

Spring recognizes this and offers advisors, which combine advice and pointcuts into one object.

More specifically, the PointcutAdvisor does this.

public interface PointcutAdvisor {
   Pointcut getPointcut();
   Advice getAdvice();
}

Most of Spring’s built-in pointcuts also have a corresponding PointcutAdvisor. This is convenient if you want to define a pointcut and the advice it is managing in one place.

Read more in Spring in Action, 3rd Edition

Sanpshots

enter image description hereenter image description here

Tags:

Java

Aop

Spring