@AfterReturning(pointcut)
和@AfterReturning(value)
有什么区别
@AfterReturning(pointcut = "execution(* my.java.model.Triangle.myTest*(param))", returning = "returnedString", argNames = "param,returnedString")
public void afterReturningAdvice(String param, String returnedString) {
System.out.println("Executing after function advice that accepts the input " + param + " and returns " + returnedString);
}
上面的方法产生
Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 name binding only allowed in target, this, and args pcds
。用上面的代码替换上面的代码后,它可以正常工作
@AfterReturning(value = "(* my.java.model.Triangle.myTest*(*)) && args(param)", returning = "returnedString", argNames = "param,returnedString")
public void afterReturningAdvice(String param, String returnedString) {
System.out.println("Executing after function advice that accepts the input " + param + " and returns " + returnedString);
}
价值和切入点有什么区别
最佳答案
实际上,当使用切入点表达式时,如果在指定时覆盖了文学价值子句,则可以复制指定将建议从值绑定到切入点的表达式,反之亦然,请选中here
之所以会出现异常,是因为AfterReturning仅隐式绑定返回值,如果要绑定任何参数,则必须在第一个表达式中添加&& args(param):
@AfterReturning(pointcut = "execution(* my.java.model.Triangle.myTest*(String)) && args(param)" ..
请注意,我还将
execution(* my.java.model.Triangle.myTest*(param)
更改为execution(* my.java.model.Triangle.myTest*(String)
因为执行(..)与advisor的绑定参数无关,所以它仅匹配方法执行连接点。
关于java - @AfterReturning(切入点)vs @AfterReturning(值),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48955420/