I’ve created very basic aspectJ project. I have no idea why advice cannot be applied.
annotation
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
public @interface Conditional {
String value();
}
and aspectJ class:
@Aspect
public class AspectE {
@Around("call(@Conditional * *.*(..)) && @annotation(conditional)" )
public Object condition(ProceedingJoinPoint joinPoint, Conditional conditional) throws Throwable {
System.out.println("entry point says hello!");
return joinPoint.proceed();
}
}
main:
public class Main {
@Conditional("")
public static void main(String[] args) {
System.out.println("main good morning");
}
}
Could you please tell me what I should change to receive both messages?
I think it is because of the
call(@Conditional * *.*(..))which basically weaves the callers , the caller in this specific case is the command line and so there is no weaving happening.You should probably change it to execution instead, that should work.
@Around("execution(@Conditional * *.*(..)) && @annotation(conditional)" )