![](/img/trans.png)
[英]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.