【发布时间】:2012-04-12 04:20:18
【问题描述】:
我有一个带有一些简单 REST 服务请求的 Spring MVC 控制器。当从我的服务中抛出特定异常时,我想添加一些错误处理,但是我无法让使用 @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!");
}
【问题讨论】:
标签: java rest spring-mvc