【发布时间】:2019-06-15 00:37:24
【问题描述】:
我正在使用 Spring Boot 并使用 AbstractErrorController 编写一个全局异常处理程序。如何在控制器中获取异常对象?
@Controller
public class MyCustomErrorController extends AbstractErrorController {
public MyCustomErrorController(ErrorAttributes errorAttributes) {
super(errorAttributes);
}
@RequestMapping("/error")
public void handleError(HttpServletRequest req, HttpServletResponse resp) {
Exception e = ...; // how to get exception here
log.error(e);
displayError(req, resp, e);
}
@Override
public String getErrorPath() {
return "/error";
}
}
【问题讨论】:
-
我不明白这里的逻辑。您想从端点检索错误吗?通常,错误处理程序会捕获异常并为引发该异常的任何控制器返回错误。
标签: spring-boot