springMVC 报错:Circular view path [list]: would dispatch back to the current handler URL [/list] again. Check your ViewResolver setup!

昨天调用接口别人回调我的接口的时候就报这个错误:

javax.servlet.ServletException: Circular view path [list]: would dispatch back to the current handler URL [/list] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

大致是说循环的url请求,就是我的Controller返回的视图Url与该方法的访问URL相同。

我使用的是springBoot,它的配置仅仅使用的是一个@SpringBoot注解。目前项目主要的功能是与app进行交互,不存在返回jsp页面,所以并没有设置前后缀。

首先我检查我的方法的返回值:

  因为接口回调中没有要求我给返回值,所以我方法是void的。

这个是Spring Controller Method的返回值问题吗?

进行百度:

VOID的返回值类型见这个:http://www.cnblogs.com/best/p/5669010.html#_label3_1_2_0

然后关于它所言的用前缀+方法名+后缀我测试是这个样子的,但是我报错的时候出现的默认跳转url是我的请求url。有点不知道为什么。然后继续找答案,出现void的时候使用

RequestToViewNameTranslator.getViewName()获取url。
查看源码:
public interface RequestToViewNameTranslator {
    /** 
     * Translate the given {@link HttpServletRequest} into a view name. 
     * @param request the incoming {@link HttpServletRequest} providing 
     * the context from which a view name is to be resolved 
     * @return the view name (or {@code null} if no default found) 
     * @throws Exception if view name translation fails 
     */
    String getViewName(HttpServletRequest request) throws Exception;
}

public String getViewName(HttpServletRequest request) {
    String lookupPath = this.urlPathHelper.getLookupPathForRequest(request);
    return this.prefix + this.transformPath(lookupPath) + this.suffix;
}

 public String getLookupPathForRequest(HttpServletRequest request) {
    if(this.alwaysUseFullPath) {
        return this.getPathWithinApplication(request);
    } else {
        String rest = this.getPathWithinServletMapping(request);
        return !"".equals(rest)?rest:this.getPathWithinApplication(request);
    }
}

 public String getPathWithinApplication(HttpServletRequest request) {
    String contextPath = this.getContextPath(request);
    String requestUri = this.getRequestUri(request);
    String path = this.getRemainingPath(requestUri, contextPath, true);
    return path != null?(StringUtils.hasText(path)?path:"/"):requestUri;
}

  public String getPathWithinServletMapping(HttpServletRequest request) {
        String pathWithinApp = this.getPathWithinApplication(request);
        String servletPath = this.getServletPath(request);
        String sanitizedPathWithinApp = this.getSanitizedPath(pathWithinApp);
        String path;
        if(servletPath.contains(sanitizedPathWithinApp)) {
            path = this.getRemainingPath(sanitizedPathWithinApp, servletPath, false);
        } else {
            path = this.getRemainingPath(pathWithinApp, servletPath, false);
        }

        if(path != null) {
            return path;
        } else {
            String pathInfo = request.getPathInfo();
            if(pathInfo != null) {
                return pathInfo;
            } else {
                if(!this.urlDecode) {
                    path = this.getRemainingPath(this.decodeInternal(request, pathWithinApp), servletPath, false);
                    if(path != null) {
                        return pathWithinApp;
                    }
                }

                return servletPath;
            }
        }
    }

说实话,还是有点懵逼。我的解决方式是将void返回替换成String的返回,返回"".这样就不报错了。

 

posted @ 2017-06-23 11:00  guodaxia  阅读(1361)  评论(0)    收藏  举报