@RestControllerAdvice
public class GlobalExceptionHandler {
private static Logger logger = LoggerFactory.getLogger("error");
@ExceptionHandler(value = Exception.class)
@ResponseBody
public Map<String, String> defaultErrorHandler(final HttpServletRequest request, final Exception ex) {
String requestURI = request.getRequestURI();
String exceptionStackTrace = ExceptionUtils.getStackTrace(ex);
logger.error("uri: {}, ex: {}", requestURI, exceptionStackTrace);
return ImmutableMap.of("uri", requestURI, "ex", exceptionStackTrace);
}
}
spring 全局异常拦截器
最新推荐文章于 2024-06-13 14:23:35 发布