当我要访问一些不存在的页面时,我试图在我的Spring启动+ Hibernate服务器上捕获404错误(例如http://localhost:8080/tes(http://localhost:8080/test正在运行))。我已经创建了@ControllerAdvice类,但它无法捕获404异常(其他工作正常)。什么问题?
@ControllerAdvice
public class GlobalExceptionHandlerController {
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ExceptionHandler(value = NullPointerException.class)
@ResponseBody
public String handleNullPointerException(Exception e) {
System.out.println("A null pointer exception ocurred " + e);
return "nullpointerExceptionPage";
}
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(value = Exception.class)
@ResponseBody
public String handleAllException(Exception e) {
System.out.println("A unknow Exception Ocurred: " + e);
return "unknowExceptionPage";
}
@ExceptionHandler(NoHandlerFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public String handleResourceNotFoundException() {
return "notFoundJSPPage";
}