EL1008E:在'java.util.HashMap'类型的对象上找不到属性或字段'timestamp' - 可能不公开?

时间:2017-05-03 04:33:46

标签: java spring spring-boot spring-el

当我使用Spring Boot的全局异常处理程序时,我得到了这个:

  

org.springframework.expression.spel.SpelEvaluationException:EL1008E:   在类型的对象上找不到属性或字段'timestamp'   'java.util.HashMap' - 也许不公开?

这是我的代码,我在项目中导入了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
@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;
    }
}

1 个答案:

答案 0 :(得分:5)

您的观看名称应为&#34;错误&#34;但不是&#34; / error&#34;,视图解析器会在模板文件夹中找到名为error.html的模板,如果视图解析器找不到它,它将使用默认值,其中需要时间戳。模型。

相关问题