使用AspectJ自定义注释
自定义注释
@Documented
@Target(ElementType.METHOD)
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface Loggable {
String getString() default "";
boolean print() default true;
}
方面
@Before("execution(@Loggable * *.*(..))")
public void myBeforeAdvice(JoinPoint jp) {
System.out.println("Before List");
Object[] parameterList = jp.getArgs();
System.out.println("Length=="+ parameterList.length);
System.out.println("After List");
//return returnVal;
}
自定义注释使用
@Loggable(getString="Custom", print=true)
public String run(){
System.out.println("Inside Run Method");
return "Returning Method Run!";
}
OutPut
Before List
Length==0
After List
Inside Run Method
如何获取自定义注释的参数,因为我根据参数做出了一些决定! i.e print may be true / false
更新我!
答案 0 :(得分:1)
before(Loggable l) : call(@Loggable * *.*(..)) && @annotation(l);
认为它类似于基于注释的切入点。