I'm facing a strange behaviour using AspectJ for a pointcut using my custom annotation.
The pointcut I use is:
@AfterThrowing(pointcut="@annotation(com.core.meta.NotifyOnFailure)", throwing="ex")
The problem I have is that my aspect is executed twice but if I modify the pointcut to:
@AfterThrowing(pointcut="execution(* sendAndReceive(..))", throwing="ex")
It runs once as expected.
The only method I have that raises the aspect is this:
@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;
}
Any idea about why my aspect is executed twice when using my custom annotation and only once when I use execution
pointcut?