Caused by: java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
阿新 • • 發佈:2018-12-22
切入點引數定義錯誤
錯誤詳細資訊如下,紅色標註是錯誤的關鍵點
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);
}