I have a scenario where my method to be intercepted is in the parent class and is not overridden in the pointcut class. Here is the sample classes:
public abstract class A{
@RequestMapping(value = "/data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String getData(@RequestBody String request) throws Exception {
return "dummy";
}
}
@RestController
public class B extends A {
}
My Aspect is defined as:
@Aspect
@Component
public class RestCallLogger {
@Pointcut("within(com.test..*) && within(@org.springframework.web.bind.annotation.RestController *)")
public void restControllers() {
}
@Pointcut("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void requestMappingAnnotations() {
}
@Around("restControllers() && requestMappingAnnotations()")
public Object onExecute(ProceedingJoinPoint jp) throws Throwable {
Object result = null;
try {
result = jp.proceed();
} catch (Exception ex) {
throw ex;
}
return result;
}
}
But its not working. If I mark class A with Annotation @RestController and make it concrete, then it works. The question is how can I create a "pointcut for method in parent abstract class"? PS: I can not change the hierarchy of the code as its the existing code.