目前用的方法是@RestControllerAdvice
及@ExceptionHandler
,捕获抛出的异常(即500错误)。
但是如果是Request method 'GET' not supported
(即405错误),则无法正常返回,得到的也是500错误。
SpringBoot中负责错误返回消息的是BasicErrorController
,其通过父类AbstractErrorController
的getStatus()
方法获取HttpStatus
,怎么才能像BasicErrorController
那样获取正确的HttpStatus
返回给页面?
spring boot 捕获404错误 ErrorController