1. 程式人生 > >springboot新版本(2.0.0+)自定義ErrorController中使用ErrorAttributes

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

map bool his servle ror nbsp ace 自定義error erro

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