我浏览了链接:如何在 Spring MVC 中的 @controllerAdvice 或 @RestControllerAdvice 中找到控制器名称?很多次,但我希望在 @ControllerAdvice 类中获取控制器方法名。
这是我的 CustomHandler 类。
@ControllerAdvice
public class CustomExceptionHandler extends ResponseEntityExceptionHandler {
........
..........
..........
@ExceptionHandler({DataExistsException.class})
public ResponseEntity<Object> handleDataExistsException(RuntimeException e, WebRequest request, HttpServletRequest httpRequest, HttpServletResponse response, HandlerMethod handlerMethod) {
// Here I am looking to print Controller endpoint method name
LoggingUtil.printJsonReq(httpRequest, HttpStatus.valueOf("BAD_REQUEST").value(), LoggingUtil.getTime(httpRequest), null, response);
return handleExceptionInternal(e, getErrors(error), getHeaders(), HttpStatus.BAD_REQUEST, request);
}
}