spring boot以json格式提供如下错误:
{
"timestamp": "2019-01-17T16:12:45.977+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Error processing the request!",
"path": "/endpoint"
}
我是否可以在数据库中获取此错误 ErrorController
然后继续?
@Controller
public class CustomErrorController implements ErrorController {
@RequestMapping("/error")
public String handleError(Model model) {
// how to get json-error here?
model.addAttribute("resultJson", ?);
return "error";
}
}
它在房间里吗 HttpServletResponse
或者别的什么?
1条答案
按热度按时间qncylg1j1#
默认值
error
属性是从WebRequest
使用ErrorAttributes
豆子。spring已经提供了这个bean的默认实现
DefaultErrorAttributes
豆子。您可以让容器像任何普通bean一样将此bean注入到自定义/错误控制器实现中,以便使用它: