spring-aop/spring-aop-advice/README.md
✒️ 作者 - Lex 📝 博客 - 掘金 📚 源码地址 - github
Advice接口是Spring AOP中的核心接口之一,用于定义在切面逻辑中要执行的操作。它允许我们在目标方法执行前、执行后、抛出异常时等不同的连接点上添加自定义的行为。Advice接口的实现类可以通过方法拦截器(MethodInterceptor)、前置通知(BeforeAdvice)、后置通知(AfterReturningAdvice)、异常通知(ThrowsAdvice)等方式来实现不同类型的通知逻辑。
定义通知逻辑
支持不同类型的通知
Advice接口的实现类可以实现不同类型的通知逻辑,如前置通知、后置通知、环绕通知、异常通知等。与切点结合
Advice通常与切点(Pointcut)结合使用,以确定通知应该在哪些连接点上执行。应用于Advisor
Advice通常作为Advisor的一部分,与切点结合,以实现切面的逻辑。Advice接口是Spring AOP中的一个标签接口,用于定义各种类型的通知,例如拦截器。通过实现该接口,我们可以定义在方法执行前、执行后、抛出异常时等不同连接点上执行的操作,从而实现对应用程序行为的干预和控制。
/**
* Advice的标签接口。实现可以是任何类型的通知,例如拦截器。
*
* 该接口用于定义通知。通知可以是在方法执行前、执行后、抛出异常时等不同连接点上执行的操作。
* 实现该接口的类可以是拦截器(Interceptors)等任何类型的通知。
*
* @author Rod Johnson
* @version $Id: Advice.java,v 1.1 2004/03/19 17:02:16 johnsonr Exp $
*/
public interface Advice {
}
AfterAdvice(后置通知)
AfterReturningAdvice(返回后通知)
BeforeAdvice(前置通知)
ConstructorInterceptor(构造器拦截器)
Interceptor(拦截器)
IntroductionInterceptor(引介拦截器)
MethodBeforeAdvice(方法前置通知)
MethodInterceptor(方法拦截器)
ThrowsAdvice(异常通知)
classDiagram
direction BT
class Advice {
<<Interface>>
}
class AfterAdvice {
<<Interface>>
}
class AfterReturningAdvice {
<<Interface>>
}
class BeforeAdvice {
<<Interface>>
}
class ConstructorInterceptor {
<<Interface>>
}
class Interceptor {
<<Interface>>
}
class IntroductionInterceptor {
<<Interface>>
}
class MethodBeforeAdvice {
<<Interface>>
}
class MethodInterceptor {
<<Interface>>
}
class ThrowsAdvice {
<<Interface>>
}
AfterAdvice --> Advice
AfterReturningAdvice --> AfterAdvice
BeforeAdvice --> Advice
ConstructorInterceptor --> Interceptor
Interceptor --> Advice
IntroductionInterceptor --> Advice
IntroductionInterceptor --> MethodInterceptor
MethodBeforeAdvice --> BeforeAdvice
MethodInterceptor --> Interceptor
ThrowsAdvice --> AfterAdvice