在这种情况下如何避免双重记录?
@AfterThrowing(pointcut="execution(String greeting(..))",throwing="e")
public void itsAFoo1(JoinPoint joinPoint, RemoteException e) {
logger.error(joinPoint.getSignature().toLongString() + " exception here!");
}
@After("execution(String greeting(..))")
public void itsAFoo2(JoinPoint joinPoint, RemoteException e) {
logger.error(joinPoint.getSignature().toLongString());
}
我有两个日志:
[2012-08-07 17:02:01,585] [request1344351718430] [public java.lang.String componentC.Hello.greeting(java.lang.String) exception here!]
[2012-08-07 17:02:01,585] [request1344351718430] [public java.lang.String componentC.Hello.greeting(java.lang.String)]
但如果有异常(exception),我需要收到一份,如果没有异常(exception),我需要收到一份。
最佳答案
将@After更改为@AfterReturning
@AfterReturning("execution(String greeting(..))")
public void itsAFoo2(JoinPoint joinPoint, RemoteException e) {
logger.error(joinPoint.getSignature().toLongString());
}
关于java - 如何在AspectJ中使用@After和@AfterThrowing之一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11859568/