我正在使用Spring MVC 3构建一个使用RESTful Web服务的Web应用程序.应用程序将使用Web服务,因此永远不应该真正解决对视图的任何请求.有没有办法在servlet上下文中指定没有请求应解析到任何视图?
目前,我有:
我知道尝试解决对jsp
文件夹中相应命名的视图的任何请求.但是,如果我删除它,应用程序只是尝试使用默认的视图解析器.
我担心的原因是我的应用程序日志将充满以下消息(即使它工作正常):
SEVERE: Servlet.service() for servlet [DispatcherServlet] in context with path [/vouchd] threw exception [Circular view path [signup]: would dispatch back to the current handler URL [/vouchd/signup] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause javax.servlet.ServletException: Circular view path [signup]: would dispatch back to the current handler URL [/vouchd/signup] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
或者InternalViewResolver
:
WARN [http-bio-8080-exec-4] (DispatcherServlet.java:1057) - No mapping found for HTTP request with URI [/app/WEB-INF/jsp/call.jsp] in DispatcherServlet with name 'DispatcherServlet'
我猜这两个邪恶中的两个更好.我不想关闭记录WARN级别.
试试吧@ResponseStatus
.此代码返回204,没有内容和视图解析被跳过:
@ResponseStatus(NO_CONTENT) void noView() { //... }
如果要返回原始数据并将其序列化为JSON或XML,请使用@ResponseBody
:
@ResponseBody MyPojo noView() { return new MyPojo(); }