测试spring boot定制的错误页面时,发现在页面获取exception、message的值为空
//自定义异常
public class MyException extends RuntimeException{
public MyException(){
super("抛出MyException异常");
}
}
//Controller层代码
@RequestMapping("/errorTest")
@ResponseBody
public String errorTest(){
throw new MyException();
}
<h1>5xx</h1><br>
<h2>页面错误能够获取的信息:</h2>
<h4>timestamp(时间戳):<span>[[${timestamp}]]</span></h4>
<h4>status(状态码): <span>[[${status}]]</span></h4>
<h4>error(错误提示):<span>[[${error}]]</span></h4>
<h4>exception(异常对象):<span>[[${exception}]]</span></h4>
<h4>message(异常信息):<span>[[${message}]]</span></h4>
结果
解决办法:在配置文件中编写以下设置
#server错误信息要包含异常对象和异常信息(springboot2.0以上的版本需要在配置文件中指定):
server.error.include-exception=true
server.error.include-message=always
正常显示: