I have a rest controller and Spring AOP class which catches service level custom exceptions and logs them but I also need to log the exceptions from controller side.
Here's my Spring AOP class;
@Aspect
@Component
public class ExceptionLoggerAspect {
@AfterThrowing(pointcut = "execution(* com.b.m.service.GaService.*(..)) ", throwing = "ex")
public void logError(JoinPoint joinPoint, GaException ex) {
Signature signature = joinPoint.getSignature();
String methodName = signature.getName();
String stuff = signature.toString();
String arguments = Arrays.toString(joinPoint.getArgs());
LOGGER.error("Exception have been caught in method:\n "
+ "[" + methodName + "] with arguments "
+ arguments + " and the full toString: [" + stuff + "] \n the exception is: ["
+ ex.type.getMessage() + " - " + ex.type.getAdditionalInfo() + "]");
}
}
How can I add my controller class here to log the exceptions? I added my controller package path with "execution" pointcut but it doesn't work.