Spring AOP - @AfterThrowing
Spring AOP - @AfterThrowing
当我的系统抛出异常时应该调用下面的方法,但实际上没有。它仅在我从注释中删除 'throwing' 和 'Exception' 作为参数时才有效:
无效:
@AfterThrowing(pointcut="execution(public * br.com.ogfi.*.controller.*.*(..))", throwing="e")
public void afterThrowing(Exception e) {
System.out.println("Test");
}
作品:
@AfterThrowing(pointcut="execution(public * br.com.ogfi.*.controller.*.*(..))")
public void afterThrowing() {
System.out.println("Test");
}
有谁知道我做错了什么吗?
这是整个class:
package br.com.ogfi.portalbackoffice.aspect;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class AfterThrowAdvice {
@AfterThrowing(pointcut="execution(public * br.com.ogfi.*.controller.*.*(..))", throwing="e")
public void afterThrowing(Exception e) {
System.out.println("Boo! We want our money back!");
//ex.printStackTrace();
//System.out.println("Boo! We want our money back!");
}
}
我终于找到了它不起作用的原因:
我正在使用的 java 项目有自己的异常,称为 SystemException,与 javax.transaction.SystemException 同名,我还没有意识到它不是来自 javax .
我的项目中的 SystemException 扩展了 Throwable,当我尝试使用 Exception 作为参数时,我的方法没有被调用,因为不是同一回事。
当我的系统抛出异常时应该调用下面的方法,但实际上没有。它仅在我从注释中删除 'throwing' 和 'Exception' 作为参数时才有效:
无效:
@AfterThrowing(pointcut="execution(public * br.com.ogfi.*.controller.*.*(..))", throwing="e")
public void afterThrowing(Exception e) {
System.out.println("Test");
}
作品:
@AfterThrowing(pointcut="execution(public * br.com.ogfi.*.controller.*.*(..))")
public void afterThrowing() {
System.out.println("Test");
}
有谁知道我做错了什么吗?
这是整个class:
package br.com.ogfi.portalbackoffice.aspect;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class AfterThrowAdvice {
@AfterThrowing(pointcut="execution(public * br.com.ogfi.*.controller.*.*(..))", throwing="e")
public void afterThrowing(Exception e) {
System.out.println("Boo! We want our money back!");
//ex.printStackTrace();
//System.out.println("Boo! We want our money back!");
}
}
我终于找到了它不起作用的原因:
我正在使用的 java 项目有自己的异常,称为 SystemException,与 javax.transaction.SystemException 同名,我还没有意识到它不是来自 javax .
我的项目中的 SystemException 扩展了 Throwable,当我尝试使用 Exception 作为参数时,我的方法没有被调用,因为不是同一回事。