Cho*_*ang 10 java spring spring-el spring-boot
当我使用Spring Boot的全局异常处理程序时,我得到了:
org.springframework.expression.spel.SpelEvaluationException:EL1008E:在'java.util.HashMap'类型的对象上找不到属性或字段'timestamp' - 可能不公开?
这是我的代码,我在我的项目中导入了Spring Security和Thymeleaf.
<!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
Run Code Online (Sandbox Code Playgroud)
@GetMapping("/test")
public String test() throws Exception {
throw new Exception("????");
}
Run Code Online (Sandbox Code Playgroud)
@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;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16054 次 |
最近记录: |