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

Posted king西阳

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);
}
 

 

以上是关于springboot新版本(2.0.0+)自定义ErrorController中使用ErrorAttributes的主要内容,如果未能解决你的问题,请参考以下文章