【问题标题】:Spring RESTful web service Unmapped URI Exception HandlingSpring RESTful Web 服务未映射的 URI 异常处理
【发布时间】: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 看起来像, 地图> 豆> 豆> 属性> 豆> 豆> 列表> 属性> 豆> /WEB-INF/pages/属性> .jsp属性> 豆> 豆> 豆> 豆>

当我点击 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


    【解决方案1】:

    这就是我所做的。我创建了一个controller 来处理404 而不是JSP,因为我无法解决JSP 的问题。它按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 1970-01-01
      • 2016-09-28
      • 2022-06-19
      相关资源
      最近更新 更多