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

     
  • 相关阅读:
    RII K25A 语音空中飞鼠 红外学习步骤
    淘宝导航栏颜色修改
    上海巨人网络参与网络诈骗整个流程
    xp的停止更新对我们有什么影响?
    USB3.0 和usb 2.0的区别
    一些有意思的脑际急转弯
    淘宝上 1200左右的组装电脑,真的性价比很高么?
    【图文教程】用“iz3d”软件将您的游戏打造为红蓝3D游戏。
    网上下载的“上下3D”和“左右3D”影片该如何播放?
    电脑cmos是什么?和bois的区别?
  • 原文地址:https://www.cnblogs.com/Courage129/p/12674748.html
Copyright © 2011-2022 走看看