Scott
Scott

Reputation: 9488

AOP Advice around RequestMapping

How can I create a Pointcut around my methods annotated with @RequestMapping?

I have a Pointcut defined that I'd like to restrict a bit further:

@Pointcut("execution(public * company.controllers.AbstractController+.*(..))")
public void methodPointcut() { }

Is it possible to further restrict that to only methods which are annotated with @RequestMapping?

I tried adding && @annotation to the end of the Pointcut, but that is not a well formed Pointcut.

Upvotes: 1

Views: 2952

Answers (2)

Scott
Scott

Reputation: 9488

I think this was easiest to do with two Pointcuts.

@Pointcut("execution(public * company.controllers.AbstractController+.*(..))")
public void methodPointcut() {}

and

@Pointcut("within(@org.springframework.web.bind.annotation.RequestMapping *)")
public void requestMapping() {}

Then simply doing:

@Before("methodPointcut() && requestMapping()")

Upvotes: 1

RonU
RonU

Reputation: 5785

You can specify annotations in a pointcut:

@Pointcut("execution(@RequestMapping public * company.controllers.AbstractController+.*(..))")
public void methodPointcut() { } 

Is this something you've already tried?

Upvotes: 2

Related Questions