相关疑难解决方法(0)

从ProceedingJoinPoint中检索参数值

在我的请求中,我有一个参数名称"accessToken",如何从ProceedingJoinPoint获取请求参数值?

public Object handleAccessToken(ProceedingJoinPoint joinPoint) throws Throwable { 
    final Signature signature = joinPoint.getStaticPart().getSignature();
    if (signature instanceof MethodSignature) {
        final MethodSignature ms = (MethodSignature) signature;
        String[] params = ms.getParameterNames();
        for (String param : params) {
            System.out.println(param);
            // here how do i get parameter value using param ?
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

通话方式:

public MyResponse saveUser(
    @RequestParam("accessToken") String accessToken,
    @RequestBody final UserDto userDto
) {
    // code 
}
Run Code Online (Sandbox Code Playgroud)

我想在AOP中获取此访问令牌.

提前致谢.

aop spring-aop spring-aspects

9
推荐指数
2
解决办法
2万
查看次数

具有带注释参数的切入点匹配方法

在以下情况下,我需要使用与方法匹配的切入点创建方面:

  1. 它是用MyAnnotationForMethod注释的
  2. 其中一个参数(可以有很多)用@MyAnnotationForParam注释(但也可以有其他注释).

方面类看起来像这样

@Pointcut("execution(@MyAnnotationForMethod * *(..,@aspects.MyAnnotationForParam Object, ..)) && args(obj)")
void myPointcut(JoinPoint thisJoinPoint, Object obj) {
}

@Before("myPointcut(thisJoinPoint ,  obj)")
public void doStuffOnParam(JoinPoint thisJoinPoint, Object obj) {
    LOGGER.info("doStuffOnParam :"+obj);
}
Run Code Online (Sandbox Code Playgroud)

注释方法

@MyAnnotationForMethod
public string theMethod(String a, @MyAnnotationForParam @OtherAnnotation Object obj, Object b){ 
    LOGGER.info(a+obj+b);
}
Run Code Online (Sandbox Code Playgroud)

用eclipse - >警告:关于poincut:

Multiple markers at this line 
    - no match for this type name: MyAnnotationForMethod [Xlint:invalidAbsoluteTypeName] 
    - no match for this type name: aspects.MyAnnotationForParam On the before : advice defined in xxx.xxx.xxx.xxx.MyAspect has not …
Run Code Online (Sandbox Code Playgroud)

java parameters aop annotations aspectj

8
推荐指数
1
解决办法
9265
查看次数