Java – the difference between Advisor and Aspect in AOP

aopjavaspring

I am new to Spring AOP. Based on my understanding, I noticed that both Advisor (for example DefaultPointcutAdvisor) and Aspect (for example the class annotated with @Aspect) can both help to solve the cross-cutting problem by doing something more when a method is invoked.

What is the different between these two term please?

Best Answer

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 here enter image description here