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

版权声明:博客知识产权来源命运的信徒,切勿侵权 https://blog.csdn.net/qq_37591637/article/details/85162614

 切入点参数定义错误

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

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);
		
	}

猜你喜欢

转载自blog.csdn.net/qq_37591637/article/details/85162614