看到https://www.cnblogs.com/15ho/p/5964279.html这篇博客才发现我的错误
在配置时
<!-- 配置切面及通知 -->
<aop:aspect ref="loggingAspect" order="2">
<aop:before method="beforeMethod" pointcut-ref="pointcut"/>
<aop:after method="afterMethod" pointcut-ref="pointcut"/>
<aop:after-throwing method="afterThrowingMethod" pointcut-ref="pointcut"/>
<aop:after-returning method="afterReturningMethod" pointcut-ref="pointcut"/>
</aop:aspect>
<aop:aspect ref="vlidationAspect" order="1">
<aop:before method="ValidateArgs" pointcut-ref="pointcut"/>
</aop:aspect>
对应的LoggingAspect类中关于返回通知和异常通知都是有两个参数的,包括一个JoinPoint
public void afterReturningMethod(JoinPoint joinPoint,Object result) {
String methodName=joinPoint.getSignature().getName();
System.out.println("method ends "+methodName+" ends with "+result);
}
public void afterThrowingMethod(JoinPoint joinPoint,Object ex) {
String methodName=joinPoint.getSignature().getName();
System.out.println("method ends "+methodName+" occurs exception "+ex);
}
所以在配置的时候应该将除了JoinPoint参数外的参数都添加到配置中,变量名必须保持一致
<aop:after-throwing method="afterThrowingMethod" pointcut-ref="pointcut" throwing="ex"/>
<aop:after-returning method="afterReturningMethod" pointcut-ref="pointcut" returning="result"/>
刚学spring,关于JoinPoint这个参数为什么不用写,还不知道。等大体学完在回顾这些细节