【发布时间】:2019-06-04 14:07:37
【问题描述】:
我有一个简单的 Spring MVC 应用程序,我想在其中使用 @ControllerAdvice 处理所有未映射的 url。
这是控制器:
@ControllerAdvice
public class ExceptionHandlerController {
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NoHandlerFoundException.class)
public String handle404() {
return "exceptions/404page";
}
}
不过,每次都会得到 Whitelabel Error Page。
我尝试使用RuntimeException.class、HttpStatus.BAD_REQUEST 并使用NoHandlerFoundException 扩展类,但没有用。
有什么建议吗?
【问题讨论】:
标签: java spring spring-boot spring-mvc error-handling