gpt4 book ai didi

java - AspectJ:一个方面内多个通知的执行顺序(优先级)

转载 作者:搜寻专家 更新时间:2023-10-31 08:20:33 24 4
gpt4 key购买 nike

类使用编译时编织。

假设我有方面类:

@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 确定执行顺序的正确方法是什么?

最佳答案

请阅读 language semantics 中的“建议优先级”段落AspectJ 文档的一部分。

方面的优先级可以明确声明,单个方面内的建议的优先级由文档中描述的规则决定,不能更改,AFAIK。所以在这种情况下,@DeclarePrecedence 不会帮助您,只会更改方面文件中通知的顺序。

关于java - AspectJ:一个方面内多个通知的执行顺序(优先级),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11850160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com