【发布时间】:2015-05-15 00:52:44
【问题描述】:
我在使用 AspectJ 使用我的自定义注释作为切入点时遇到了一个奇怪的行为。
我使用的切入点是:
@AfterThrowing(pointcut="@annotation(com.core.meta.NotifyOnFailure)", throwing="ex")
我遇到的问题是我的方面被执行了两次,但是如果我将切入点修改为:
@AfterThrowing(pointcut="execution(* sendAndReceive(..))", throwing="ex")
它按预期运行一次。
我唯一能提高方面的方法是:
@NotifyOnFailure // I want to use this annotation to raise the aspect once
public String sendAndReceive(String serviceUrl)
{
String responseXml = "...";
try
{
throw new Exception("test...");
}
catch(Exception x)
{
ExternalExecutionException ex = new ExternalApiExecutionException("Service failed");
throw ex;
}
finally
{
...
}
return responseXml;
}
知道为什么我的切面在使用自定义注释时执行两次,而在我使用execution 切入点时只执行一次?
【问题讨论】: