代码如下
@Component
public class MyErrorAttribute extends DefaultErrorAttributes {
@Override
public Map<String,Object> getErrorAttributes (WebRequest webRequest,boolean b){
Map<String, Object> errorMap = super.getErrorAttributes(webRequest,b);
errorMap.put("custommsg","出错啦!");
errorMap.remove("error");
return errorMap;
}
}
应改为如下代码,才不会报错
public class MyErrorAttribute extends DefaultErrorAttributes { public Map<String,Object> getErrorAttributes (WebRequest webRequest, ErrorAttributeOptions options){ Map<String, Object> errorMap = super.getErrorAttributes(webRequest,options); errorMap.put("custommsg","出错啦!"); errorMap.remove("error"); return errorMap; } }