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

网上太多关于通过 @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.

参考:

  • weiku.co/article/157/
  • http://forum.thymeleaf.org/Thymeleaf-3-Exception-Handling-td4029725.html
  • https://stackoverflow.com/questions/31265649/how-to-catch-a-thymeleaf-view-rendering-exception-with-spring

你可能感兴趣的:(SpringBoot)