当前位置: 代码迷 >> 综合 >> Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
  详细解决方案

Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

热度:25   发布时间:2023-11-19 21:46:54.0

 切入点参数定义错误

 错误详细信息如下,红色标注是错误的关键点

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'IStudentMgr' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut

我做的是Spring 的Aop练习

产生该错误的原因是我们在使用AfterReturning注解的时候,没有定义返回的参数,但是拦截的方法中缺需要传入一个参数,比如下面的“_result”参数。如果AfterReturing注解拦截的方法需要接收参数,需要在AfterReturning中声明

错误代码

@AfterReturning("execution(public int cn.com.day01.CalculatorImp.*(..))")public void afterReturn(JoinPoint joinpoint,Object result){String name=joinpoint.getSignature().getName();System.out.println("the method " + name + "is end"+result);}

正确代码

@AfterReturning(value="execution(public int cn.com.day01.CalculatorImp.*(..))",returning="result")public void afterReturn(JoinPoint joinpoint,Object result){String name=joinpoint.getSignature().getName();System.out.println("the method " + name + "is end"+result);}

 

  相关解决方案