问题描述
我是 Spring AOP 的新手.根据我的理解,我注意到 Advisor(例如 DefaultPointcutAdvisor
)和 Aspect(例如用 @Aspect
注释的类)都可以帮助解决横切在调用方法时执行更多操作的问题.
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?
推荐答案
大多数方面都是建议的组合,它定义了方面的行为和切入点定义方面应该在哪里执行.
Most aspects are a combination of advice that defines theaspect’s behavior and a pointcut defining where the aspect should be executed.
Spring 认识到了这一点,并提供了顾问,将建议和切入点结合起来成一个对象.
Spring recognizes this and offers advisors, which combine advice and pointcutsinto one object.
更具体地说,PointcutAdvisor
就是这样做的.
More specifically, the PointcutAdvisor
does this.
public interface PointcutAdvisor {
Pointcut getPointcut();
Advice getAdvice();
}
大多数 Spring 的内置切入点也有相应的 PointcutAdvisor
.如果你想定义一个切入点和它正在管理的通知,这很方便一处.
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 managingin one place.
截图
这篇关于AOP 中的 Advisor 和 Aspect 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!