在测试基于注解编程过程中,出现如下异常:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'calculatorImpl' defined in file [D:\Java\SSM\ssm-my\SSM\spring-aop\spring-aop\target\classes\com\hsbc\aop\CalculatorImpl.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
Java源代码:
// 返回通知,指明目标方法的返回值 "returning" @AfterReturning(value = "pointcut()", returning = "result") public void afterReturnAdviceMethod(Object result, JointPoint joinPoint) { System.out.println("------------------Return Advice--------------------"); System.out.println("目标方法返回值结果" + result); System.out.println("------------------Return Advice--------------------"); System.out.println(); System.out.println(); }
异常说明是Bean初始化异常,应该是在构建动态代理对象的过程中出现的错误。
这里的JoinPoint并没有导错包
在一顿倒腾之后发现是afterReturnAdviceMethod
方法参数的问题,必须要让JoinPoint
处于第一个参数的问题才不会出现异常。
改善之后的代码:
// 返回通知,指明目标方法的返回值 "returning" @AfterReturning(value = "pointcut()", returning = "result") public void afterReturnAdviceMethod(JointPoint joinPoint, Object result) { System.out.println("------------------Return Advice--------------------"); System.out.println("目标方法返回值结果" + result); System.out.println("------------------Return Advice--------------------"); System.out.println(); System.out.println(); }
AfterThrowing
的方法签名也有这种情况,其他尚未验证。如有问题,积极讨论