Spring aop, unbound pointcut parameter

fil*_*zyk 5 aop spring

Im getting this error taht i dont really understand:

unbound pointcut parameter auditable
Run Code Online (Sandbox Code Playgroud)

following code:

@Aspect
public class TestAspect {

    @Before(value = "@annotation(Action)")
    public void audit(JoinPoint joinPoint, Action auditable) {
        System.out.println(auditable);
    }
}

 @Action(ActionType.FAST)
    public static void resolveFast(String name){
        System.out.println(name);
    }

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Action {

    ActionType value();
    boolean withArgs() default false;
}

public enum ActionType {
    FAST, SLOW
}
Run Code Online (Sandbox Code Playgroud)

the problem occurs on @Before annotation, these are my first steps in aop...

kkk*_*kv_ 10

像这样更改代码:

    @Before(value = "@annotation(auditable)")
    public void audit(JoinPoint joinPoint, Action auditable) {
        System.out.println(auditable);
    }
Run Code Online (Sandbox Code Playgroud)

你看到不一样了吗??

对了,@annotation的参数应该是auditable!!!

好吧,现在我只是花了将近2个小时来调试......

只是这个。我觉得浪费了我的生命,但我真的希望拯救你的生命......

我还是感觉不好...


小智 9

在此声明中:

 @Before(value = "@annotation(Action)")
Run Code Online (Sandbox Code Playgroud)

您应该替换Actionauditable.


小智 2

尝试参考代码

@Before("execution(public String com.captaindebug.audit.controller.*Controller.*(..)) && @annotation(auditAnnotation)")
    public void auditScreen(JoinPoint joinPoint,Audit auditAnnotation) {...}
Run Code Online (Sandbox Code Playgroud)