I know that there are a lot of similar questions in Stackoverflow but none of them helped me.
I have a controller like this:
com.mypkg.controller;
@RestController
public class MyController {
@RequestMapping(method = RequestMethod.POST,
......
public ResponseEntity<?> MyEndpoint(myParams) {
return this.myMethod(myParams, "myString");
}
public ResponseEntity<?> myMethod(myParams, String myString){
//do something
return myReponseEntity
}
}
I defined my aspect in this way:
com.mypkg.controller;
@Aspect
@Component
@Slf4j
public class MyAspect {
@Around("execution(* com.mypkg.controller.MyController.MyEndpoint(..)) && args(..,aParam)")
public ResponseEntity<?> endpointAround(ProceedingJoinPoint joinPoint, String aParam) throws Throwable {
// I am working fine
// do something
return
}
@Around("execution(* com.mypkg.controller.MyController.myMethod(..)) && args(..,myString)")
public ResponseEntity<?> myMethodAround(ProceedingJoinPoint joinPoint, String myString) throws Throwable {
// **** I AM NOT CALLED****
// do something
// return ...
}
}
I configured the AutoProxy
@Configuration
@EnableAspectJAutoProxy(proxyTargetClass=true)
public class AopConfig {}
The function endpointAround
is called every time that I call MyEndpoint (throw the REST api).
The problem is the second @Around
. it is not called. I need to call a method everytime MyEndpoint
is exectued and another one eveytime that MyEndpoint
call myMethod
.