Spring AOP:After 或 AfterReturning 将首先调用哪个建议
Spring AOP: After or AfterReturning which advice will invoked first
假设我们在同一个 jointpoint[= 上应用了两个建议,一个是 After 类型,另一个是 AfterReturning 类型18=](业务功能)然后如果 jointpoint 成功执行 advice 将首先调用哪个
这里没有重复答案,而是 link 到 Spring AOP 描述了排序。
在同一个jointpoint(核心业务相关模块)上调用不同类型的通知如下:
1.Around
2.Before and/or After
3.AfterReturning or AfterThrowing
假设我们在同一个关节点上应用了所有五种类型的建议,那么流程将是这样的:
Around type advice will be invoked and code before pjp.proceed()
of Around type advice will be executed where pjp is the reference
variable of ProceedingJoinPoint interface.
Before type advice will be invoked and executed fully.
code inside jointpoint will be executed fully.
Code after pjp.proceed()
of Around type advice will be executed if jointpoint executes successfully otherwise skip this step and go to
step 5. If it's modified return value then this new return value will
be effected to the followings advice or method invocation.
After type advice will be invoked and executed fully.
AfterReturning type advice will be invoked and executed fully if jointpoint executes successfully else if jointpoint throws any error
then AfterThrowing type advice will be invoked and executed fully.
假设我们在同一个 jointpoint[= 上应用了两个建议,一个是 After 类型,另一个是 AfterReturning 类型18=](业务功能)然后如果 jointpoint 成功执行 advice 将首先调用哪个
这里没有重复答案,而是 link 到 Spring AOP 描述了排序。
在同一个jointpoint(核心业务相关模块)上调用不同类型的通知如下:
1.Around
2.Before and/or After
3.AfterReturning or AfterThrowing
假设我们在同一个关节点上应用了所有五种类型的建议,那么流程将是这样的:
Around type advice will be invoked and code before
pjp.proceed()
of Around type advice will be executed where pjp is the reference variable of ProceedingJoinPoint interface.Before type advice will be invoked and executed fully.
code inside jointpoint will be executed fully.
Code after
pjp.proceed()
of Around type advice will be executed if jointpoint executes successfully otherwise skip this step and go to step 5. If it's modified return value then this new return value will be effected to the followings advice or method invocation.After type advice will be invoked and executed fully.
AfterReturning type advice will be invoked and executed fully if jointpoint executes successfully else if jointpoint throws any error then AfterThrowing type advice will be invoked and executed fully.