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

     
  • 相关阅读:
    Sql Server数据库汉字按字母、笔划、拼音首字母、排序
    产生一个int数组,长度为100,并向其中随机插入1100,并且不能重复
    使用DropDownExtender
    一些关于中文乱码问题的一些解决方案和经验和大家分享!
    (译)Silverlight教程第一部分: 使用Silverlight 2 和 VS 2008创建“Hello World”程序
    使用CalendarExtender
    .NET实现中英文验证码
    使用Accordion
    使用AlwaysVisibleControlExtender
    Javascript经典窍门
  • 原文地址:https://www.cnblogs.com/Courage129/p/12674748.html
Copyright © 2011-2022 走看看