AspectJ和Spring:当方法抛出异常时,排除@After方法执行

时间:2016-07-25 15:43:37

标签: java spring aspectj

我在春天基于aspectJ:

@After("execution(* ...)
public void stopTotalTimerAndMarkSucess(JoinPoint joinPoint) {...}

@AfterThrowing("execution(* c ..)
public void markError(JoinPoint joinPoint) {...}

当我的under方法抛出异常时,我需要排除@After执行。 现在当一个方法抛出异常时(@After和@AfterThrowing)。

1 个答案:

答案 0 :(得分:2)

你需要@AfterReturning注释而不是@After。

@AfterReturning接口:

  

在匹配的方法执行返回时返回建议运行   一般。它是使用@AfterReturning注释(...)

声明的

@After:

  

在(最终)建议运行之后,匹配的方法执行退出。   它是使用@After注释声明的。建议必须   准备处理正常和异常返回条件。它是   通常用于释放资源等。

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html