我有一个Spring MVC控制器,其中包含一些简单的REST服务请求。当我的服务抛出特定的异常时,我想添加一些错误处理,但我无法使带有@ExceptionHandler注释的处理程序方法被调用。以下是一个我故意抛出异常来尝试让处理程序方法接管的服务。处理程序方法从未被调用,Spring只会向调用客户端返回500错误。你有任何关于我做错了什么的想法吗?
@ExceptionHandler(IOException.class)
public ModelAndView handleIOException(IOException ex, HttpServletRequest request, HttpServletResponse response) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
System.out.println("It worked!");
return new ModelAndView();
}
@RequestMapping(value = "/json/remove-service/{id}", method = RequestMethod.DELETE)
public void remove(@PathVariable("id") Long id) throws IOException {
throw new IOException("The handler should take over from here!");
}