本文介绍了AspectJ:一个方面内多个通知的执行顺序(优先级)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
类使用编译时编织.
假设我有方面类:
@Aspect
public class SecurityInterceptor {
@Pointcut("within(@org.springframework.stereotype.Controller *)")
public void beanAnnotatedWithController() {}
@Pointcut("execution(public * *(..)) && args(*,httpReq)")
public void publicMethods(HttpServletRequest httpReq) {}
@Pointcut("beanAnnotatedWithController() && publicMethods(httpReq)")
public void controllerMethods(HttpServletRequest httpReq) {}
@Pointcut("execution(public * *(..)) && args(httpReq)")
public void publicMethodsRequestOnly(HttpServletRequest httpReq) {}
@Pointcut("beanAnnotatedWithController() && publicMethodsRequestOnly(httpReq)")
public void controllerMethodsOneArg(HttpServletRequest httpReq) {}
@Around(value = "controllerMethods(httpReq)")
public Object populateSecurityContext(final ProceedingJoinPoint joinPoint, HttpServletRequest httpReq) throws Throwable {
return popSecContext(joinPoint, httpReq);
}
@Around(value = "controllerMethodsOneArg(httpReq)")
public Object populateSecurityContextOneArg(final ProceedingJoinPoint joinPoint, HttpServletRequest httpReq) throws Throwable {
return popSecContext(joinPoint, httpReq);
}
}
使用@DeclarePrecedence
确定执行顺序的正确方法是什么?
What is the correct way to use @DeclarePrecedence
to determine the execution order?
推荐答案
请阅读 语言语义 部分的 AspectJ 文档.
Please read paragraph "Advice precedence" in the language semantics section of the AspectJ documentation.
方面的优先级可以明确声明,单个方面内的建议的优先级由文档中描述的规则决定,不能更改,AFAIK.所以 @DeclarePrecedence
在这种情况下不会帮助你,只会改变方面文件中的通知顺序.
Precedence of aspects can be declared explicitly, precedence of advice within a single aspect is determined by rules described in the document and cannot be changed, AFAIK. So @DeclarePrecedence
will not help you in this case, only changing the order of advice within the aspect file.
这篇关于AspectJ:一个方面内多个通知的执行顺序(优先级)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!