[英]how to exclude field execution from method executions pointcut with Aspectj
[英]AspectJ and Spring: Exclude @After method execution when method throws an exception
我在春季基於AspectJ有和Aspect:
@After("execution(* ...)
public void stopTotalTimerAndMarkSucess(JoinPoint joinPoint) {...}
@AfterThrowing("execution(* c ..)
public void markError(JoinPoint joinPoint) {...}
當我的under方法拋出異常時,我需要排除@After執行。 現在,當方法引發異常時,將同時執行(@After和@AfterThrowing)。
您需要@AfterReturning批注而不是@After。
@AfterReturning:
返回建議后,當匹配的方法執行正常返回時運行建議。 使用@AfterReturning批注(...)聲明
@后:
建議(最終)運行后,匹配的方法執行退出。 它使用@After注釋聲明。 之后必須准備處理正常和異常返回條件的建議。 它通常用於釋放資源等。
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.