springboot新版本(2.0.0+)自定义ErrorController中使用ErrorAttributes

2.0.0之前使用:

@Autowired
private ErrorAttributes errorAttributes;

private Map<String, Object> getErrorAttributes(HttpServletRequest request,
                                                   boolean includeStackTrace) {
        RequestAttributes requestAttributes = new ServletRequestAttributes(request);
        return this.errorAttributes.getErrorAttributes(requestAttributes,
                includeStackTrace);
    }

后续版本使用:

@Autowired
private ErrorAttributes errorAttributes;
private Map<String, Object> getErrorAttributes(HttpServletRequest request,
boolean includeStackTrace) {
ServletWebRequest servletWebRequest = new ServletWebRequest(request);
return this.errorAttributes.getErrorAttributes(servletWebRequest,
includeStackTrace);
}
 

 

posted @ 2019-02-15 23:02  花拾夕  阅读(3600)  评论(0编辑  收藏  举报