【发布时间】:2013-01-14 02:26:10
【问题描述】:
我正在开发一个简单的 Spring REST Web 服务。根据我所做的研究,可能有两种类型的 404 异常。 例如,
@Controller
@RequestMapping("/person")
@Transactional(readOnly=true)
public class PersonController {
@RequestMapping(value="/data", method={RequestMethod.GET,RequestMethod.POST})
@ResponseStatus(value=HttpStatus.OK)
public Person getPerson() {
return service.getPerson();
}
}
类型 1:http://localhost/myws/person/get 将从 Web 服务中抛出 404。
类型 2:http://localhost/myws/idontexist 将从 Web 服务器容器中抛出 404。就我而言,它是 tomcat。
为了处理类型 1,我尝试扩展 DefaultHandlerExceptionResolver 并覆盖 handleNoSuchRequestHandlingMethod
为了处理类型 2,我在 web.xml 中添加了以下 sn-p
404错误代码>
/WEB-INF/pages/notfound.jsp 错误页面>
java.lang.Throwable /WEB-INF/pages/notfound.jsp
我的 servlet xml 看起来像,
当我点击 Type 2 URL 时,我收到以下异常。
WARN org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/myws/WEB-INF/pages/notfound.jsp] in DispatcherServlet with name 'restservlet'
但我的 JSP 存在于上述位置。可能是什么问题?
【问题讨论】:
标签: rest spring-mvc exception-handling