错误页面处理
错误页面
resources/templates/error/4xx.ftl
错误页面路径配置:server.error.path
异常处理器来进行日志输出
如抛出异常
if(one!=null){ throw new IllegalArgumentException(); }
捕获异常
1 package com.xiaoping.houseweb.controller; 2 3 import lombok.extern.slf4j.Slf4j; 4 import org.springframework.web.bind.annotation.ControllerAdvice; 5 import org.springframework.web.bind.annotation.ExceptionHandler; 6 7 import javax.servlet.http.HttpServletRequest; 8 9 @ControllerAdvice 10 @Slf4j 11 public class ErrorHandler { 12 @ExceptionHandler(value = {Exception.class,RuntimeException.class}) 13 public String error500(HttpServletRequest request,Exception e){ 14 log.error(e.getMessage(),e); 15 log.error(request.getRequestURL()+" encounter 500"); 16 return "error/500"; 17 } 18 }
结果打印日志