Spring AOP - @Around Error at ::0 切入点正式未绑定
Spring AOP - @Around Error at ::0 formal unbound in pointcut
我查看了其他 SO 问题,其中 none 个适用。关于为什么 @Before 有效,但 @Around 无效的任何想法?
在此处处理源代码:
http://www.captaindebug.com/2013/07/auditing-spring-mvc-webapp-with-aspectj.html#.VhUeIxNViko
这很好用:
@Before("execution(public String com.captaindebug.audit.controller.*Controller.*(..)) && @annotation(auditAnnotation)")
public void auditScreen(JoinPoint joinPoint,Audit auditAnnotation) {...}
但这失败并出现错误:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'mvcContentNegotiationManager': Initialization
of bean failed; nested exception is
java.lang.IllegalArgumentException: error at ::0 formal unbound in
pointcut
@Around("execution(public String com.captaindebug.audit.controller.*Controller.*(..)) && @annotation(auditAnnotation)")
public void profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {...)
这也没有用:
@Pointcut("execution(public String com.captaindebug.audit.controller.*Controller.*(..))")
public void controllerMethods() {}
@Around("controllerMethods()")
public void profile(ProceedingJoinPoint pjp) throws Throwable {}
也许你可以尝试像这样拆分切入点定义和方面?
@Pointcut("execution(public String com.captaindebug.audit.controller.*Controller.*(..))")
public void controllerMethods() {}
@Pointcut("@annotation(auditAnnotation)")
public void annotatedMethod(Audit auditAnnotation) {}
@Pointcut("annotatedMethod() && controllerMethods()")
public void annotationDrivenControllerMethodsPointcut() {}
@Around("annotationDrivenControllerMethodsPointcut()")
public void profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {...)
来自 Pointcut javadoc 文档的一些细节
When compiling without debug info, or when interpreting pointcuts at runtime, the names of any arguments used in the pointcut are not available.
@Around
必须 return 一些东西。
public Object profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {
...
Object retVal = pjp.proceed();
...
return retVal;
}
After my repeated tests
经过我的反复测试
@Around(value ="@annotation(oneAnnotaions) && args(object,..) ",argNames = "joinPoint,object," +
"oneAnnotaions")
public Object around(ProceedingJoinPoint joinPoint,Object object,com.xxx.annotaions.OneAnnotaions oneAnnotaions)
After my repeated tests
经过我的反复测试
@Around(value ="@annotation(oneAnnotaions) && args(object,..) ",argNames = "joinPoint,object," +
"oneAnnotaions")
public Object around(ProceedingJoinPoint joinPoint,Object object,com.xxx.annotaions.OneAnnotaions oneAnnotaions)
我查看了其他 SO 问题,其中 none 个适用。关于为什么 @Before 有效,但 @Around 无效的任何想法?
在此处处理源代码: http://www.captaindebug.com/2013/07/auditing-spring-mvc-webapp-with-aspectj.html#.VhUeIxNViko
这很好用:
@Before("execution(public String com.captaindebug.audit.controller.*Controller.*(..)) && @annotation(auditAnnotation)")
public void auditScreen(JoinPoint joinPoint,Audit auditAnnotation) {...}
但这失败并出现错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcContentNegotiationManager': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 formal unbound in pointcut
@Around("execution(public String com.captaindebug.audit.controller.*Controller.*(..)) && @annotation(auditAnnotation)")
public void profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {...)
这也没有用:
@Pointcut("execution(public String com.captaindebug.audit.controller.*Controller.*(..))")
public void controllerMethods() {}
@Around("controllerMethods()")
public void profile(ProceedingJoinPoint pjp) throws Throwable {}
也许你可以尝试像这样拆分切入点定义和方面?
@Pointcut("execution(public String com.captaindebug.audit.controller.*Controller.*(..))")
public void controllerMethods() {}
@Pointcut("@annotation(auditAnnotation)")
public void annotatedMethod(Audit auditAnnotation) {}
@Pointcut("annotatedMethod() && controllerMethods()")
public void annotationDrivenControllerMethodsPointcut() {}
@Around("annotationDrivenControllerMethodsPointcut()")
public void profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {...)
来自 Pointcut javadoc 文档的一些细节
When compiling without debug info, or when interpreting pointcuts at runtime, the names of any arguments used in the pointcut are not available.
@Around
必须 return 一些东西。
public Object profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {
...
Object retVal = pjp.proceed();
...
return retVal;
}
After my repeated tests 经过我的反复测试 @Around(value ="@annotation(oneAnnotaions) && args(object,..) ",argNames = "joinPoint,object," + "oneAnnotaions") public Object around(ProceedingJoinPoint joinPoint,Object object,com.xxx.annotaions.OneAnnotaions oneAnnotaions)
After my repeated tests
经过我的反复测试
@Around(value ="@annotation(oneAnnotaions) && args(object,..) ",argNames = "joinPoint,object," +
"oneAnnotaions")
public Object around(ProceedingJoinPoint joinPoint,Object object,com.xxx.annotaions.OneAnnotaions oneAnnotaions)