3

I'm trying to use Spring AOP with AspectJ support to weave methods with a certain annotation. I know it's easy to do so by using a pointcut @annotation(classname)

But I need to create weavers based on properties of the annotation. The annotation in question is Spring's @RequestMapping, and I need to check the method property of it.

I know I could access it inside the body of the advice, but what I really would like is to create one advice per matched annotation.

Is this possible?

Vinicius Carvalho
  • 3,994
  • 4
  • 23
  • 29

1 Answers1

1

There doesn't seem to be a way to do it, but you can check the parameters of the annotation immediately on entry and immediately pass it on if they're not satisfied.

@Around("execution(public * *(..)) && @annotation(reqMap)")
public Object myMethod(ProceedingJoinPoint pjp, RequestMapping reqMap)
        throws Throwable {
    if (notRightPropertyValue(reqMap))
        return pjp.proceed();
    // Do your stuff here
}

If this is too inelegant, consider inventing an extra annotation to mark just the methods that you're really interested in.

Community
  • 1
  • 1
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215