When to use @Pointcut & @Before, @After AOP Annotations
spring, spring-aop, spring-mvc
Solution
In simple words whatever you specify inside @Before or @After is a pointcut expression. This can be extracted out into a separate method using @Pointcut annotation for better understanding, modularity and better control. For example
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void requestMapping() {}
@Pointcut("within(blah.blah.controller.*) || within(blah.blah.aspect.*)")
public void myController() {}
@Around("requestMapping() && myController()")
public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable {
...............
}
As you can see instead of specifying the pointcut expressions inside `@Around`, you can separate it to two methods using `@Pointcut`.
Problem
Am learning AOP concepts in Spring. I am now pretty aware of the usages of `@Before` and `@After` Annotations and started using it for Time capturing purpose. This is pretty much satisfying all my AOP related needs. Wondering what is that `@pointcut` annotation that every spring guide talks about ? Is that a redundant functionality ? or does it has separate needs ?