When I use the Spring loader global exception handler, I got the following:
org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or timestamp of a field cannot be found on an object of type 'java.util.HashMap' - maybe not publicly?
This is my code, and I have imported Spring Security and Thymeleaf into my project.
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
<meta charset="UTF-8" />
<title>统一异常处理</title>
</head>
<body>
<h1> 系统异常 </h1>
<div th:text="${url ?: '未捕捉到URL'}"></div>
<div th:text="${exception == null ? '暂无异常信息' : exception.message}"></div>
</body>
</html
@GetMapping("/test")
public String test() throws Exception {
throw new Exception("发生错误");
}
@ControllerAdvice
public class GlobalExceptionHandler {
private static final String DEFAULT_ERROR_VIEW = "/error";
private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(value = Exception.class)
public ModelAndView defaultErrorHandler(HttpServletRequest request, Exception e) {
LOGGER.error("系统异常", e);
ModelAndView mav = new ModelAndView();
mav.addObject("exception", e);
mav.addObject("url", request.getRequestURI());
mav.setViewName(DEFAULT_ERROR_VIEW);
return mav;
}
}
source
share