我查看了其他SO问题,但没有一个适用。有关为什么@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:错误 创建名为'mvcContentNegotiationManager'的bean:初始化 豆失败;嵌套异常是 java.lang.IllegalArgumentException:错误在:: 0正式未绑定中 切入点
@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 {}
答案 0 :(得分:2)
@Around
必须返回一些东西。
public Object profile(ProceedingJoinPoint pjp, Audit auditAnnotation) throws Throwable {
...
Object retVal = pjp.proceed();
...
return retVal;
}
答案 1 :(得分:0)
也许你可以试着像这样分割切入点定义和方面吗?
@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文档中的一些详细信息
在没有调试信息的情况下编译时,或者在运行时解释切入点时,切入点中使用的任何参数的名称都不可用。
答案 2 :(得分:0)
经过我反复测试 按照我的新习惯 @Around(value ="@annotation(oneAnnotaions) && args(object,..)",argNames = "joinPoint,object," + “一个注释”) public Object around(ProceedingJoinPoint joinPoint,Object object,com.xxx.annotaions.OneAnnotaions oneAnnotaions)
答案 3 :(得分:0)
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)