[英]AspectJ and Spring: Exclude @After method execution when method throws an exception
I have and Aspect in spring based on aspectJ: 我在春季基于AspectJ有和Aspect:
@After("execution(* ...)
public void stopTotalTimerAndMarkSucess(JoinPoint joinPoint) {...}
@AfterThrowing("execution(* c ..)
public void markError(JoinPoint joinPoint) {...}
I need to exclude @After execution when my under method throws and exception. 当我的under方法抛出异常时,我需要排除@After执行。 Now when a method throws an exception are executed both (@After and @AfterThrowing).
现在,当方法引发异常时,将同时执行(@After和@AfterThrowing)。
You need @AfterReturning annotation rather than @After. 您需要@AfterReturning批注而不是@After。
@AfterReturning: @AfterReturning:
After returning advice runs when a matched method execution returns normally.
返回建议后,当匹配的方法执行正常返回时运行建议。 It is declared using the @AfterReturning annotation (...)
使用@AfterReturning批注(...)声明
@After: @后:
After (finally) advice runs however a matched method execution exits.
建议(最终)运行后,匹配的方法执行退出。 It is declared using the @After annotation.
它使用@After注释声明。 After advice must be prepared to handle both normal and exception return conditions.
之后必须准备处理正常和异常返回条件的建议。 It is typically used for releasing resources, etc.
它通常用于释放资源等。
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.