zoukankan      html  css  js  c++  java
  • SpringBoot 报错: Circular view path [readingList] 解决办法

    spring boot报错:

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

    图示:

    原因如下:

    当没有声明ViewResolver时,spring会给你注册一个默认的ViewResolver,就是JstlView的实例, 该对象继承自InternalResoureView。

    JstlView用来封装JSP或者同一Web应用中的其他资源,它将model对象作为request请求的属性值暴露出来, 并将该请求通过javax.servlet.RequestDispatcher转发到指定的URL.

    Spring认为, 这个view的URL是可以用来指定同一web应用中特定资源的,是可以被RequestDispatcher转发的。

    也就是说,在页面渲染(render)之前,Spring会试图使用RequestDispatcher来继续转发该请求。

    if (path.startsWith("/") ? uri.equals(path) : uri.equals(StringUtils.applyRelativePath(uri, path))) {
        throw new ServletException("Circular view path [" + path + "]: would dispatch back " +
                            "to the current handler URL [" + uri + "] again. Check your ViewResolver setup! " +
                            "(Hint: This may be the result of an unspecified view, due to default view name generation.)");
    }

    从这段代码可以看出,如果你的view name和你的path是相同的字符串,根据Spring的转发规则,就等于让自己转发给自己,会陷入死循环。所以Spring会检查到这种情况,于是抛出Circular view path异常。

    boot中,使用thymeleaf,会加入starter依赖,引入这个依赖的时候了,boot会自动进行配置转发规则,所以只要记得在pom文件中声明依赖即可

    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    spring中也会遇到这种情况的,原理同上,如果不声明viewResolver,就会出现这个问题的。我在controller中,不加@ResponseBody注解,直接返回"index"字符串,来映射
    index.jsp 就会进入上面的代码,判断uri 和 jsp 的name相同,都是index

     
  • 相关阅读:
    【BZOJ3218】 a+b Problem
    【BZOJ3993】 星际战争
    【BZOJ3991】 寻宝游戏
    【BZOJ2959】长跑 (LCT+并查集)
    NOIP2017记
    【CF 678F】Lena and Queries
    【Learning】多项式乘法与快速傅里叶变换(FFT)
    Subsequence Count (线段树)
    【留言板】
    【bzoj 4173】数学
  • 原文地址:https://www.cnblogs.com/Courage129/p/12674748.html
Copyright © 2011-2022 走看看