小编Pat*_*uts的帖子

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

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

  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
查看次数

标签 统计

annotations ×1

aop ×1

aspectj ×1

java ×1

parameters ×1