Spring Boot:无法捕获 Thymeleaf 模板渲染异常

此文章发布于 60 个月前,部分信息可能已经过时,请自行斟酌确认。

网上太多关于通过 @ControllerAdvice 处理全局异常的文章,但这种方式只能捕获 Controller 层的异常,如果是模板渲染发生异常(如模板文件不存在)则不会被 @ControllerAdvice 捕获到,查了一下资料没有找到理想的方法,临时只能先通过自定义 error.html 显示一下了。

有没有高手有好方法。

@ControllerAdvice annotation cannot work, because you can only use it for exception inside a controller, and here you want to process exception in a view. I'm unsure for AbstractHandlerExceptionResolver, but doc states Spring HandlerExceptionResolverimplementations deal with unexpected exceptions that occur during controller execution. But Filter method should work.

参考:

最后修改:2019 年 04 月 29 日 10 : 28 AM
如果觉得我的文章对你有用,请随意赞赏

发表评论