错误页面注册器和全局异常处理 [英] Error page registrar and Global exception handling
问题描述
我正在创建一个Spring Boot Web应用程序,但是我感到困惑的是,当出现错误页面注册器时,人们为什么使用全局异常处理程序(@ControllerAdvice)更加简洁明了。请有人可以进一步解释,是否可以从全局异常处理程序类(通过@ControllerAdvice注释的类,具有@Exceptionhandler方法)调用错误页面注册器。
I am creating a Spring Boot web application, but i am confused why people use Global Exception handlers(@ControllerAdvice) when there is Error Page Registrar which is neater and more explicit. Please can someone explain more and is it possible to call an Error page registrar from a global Exception Handler Class( class annoted with @ControllerAdvice, with an @Exceptionhandler method).
推荐答案
正如Brian回答的那样,我认为您可以做到。如果您仍然需要参考,我在这里提供了一个样本来证明这一点: https://github.com/kennytai / SampleSpringbootExceptionHandler
在此示例中,我使用 GlobalExceptionHandler
类中的 @ControllerAdvice
TestController
中的所有异常。
As Brian answer, I think you can do this. I got a sample to prove this one in here if you still need to refer: https://github.com/kennytai/SampleSpringbootExceptionHandler
At this sample, I use the @ControllerAdvice
in class GlobalExceptionHandler
to manage all exceptions from TestController
.
希望获得帮助。
这篇关于错误页面注册器和全局异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!