《Springboot极简教程》问题解决:javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL [/login] again

简介: javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL [/login] again.
javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL [/login] 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异常。

还有一种情况是,日志虽然报了这段,但是原因其实是viewResolver配置错误。

解决

通过原因分析,造成问题有两个因素:

  1. 缺省转发
  2. view和path同名

所以,解决方案如下
1.消除缺省转发
2.修改view和path,让他们不同名

相关文章
|
Java
SpringBoot启动报错:org.apache.catalina.LifecycleException: Protocol handler start failed
SpringBoot启动报错:org.apache.catalina.LifecycleException: Protocol handler start failed
453 0
|
Java 数据库连接 mybatis
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
在进行springboot和mybatis遇到了这个错误 Servlet.service() for servlet [dispatcherServlet] in context with path [] th
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
|
安全 前端开发 Java
Spring Boot 项目中触发 Circular View Path 错误的原理与解决方案
在Spring Boot开发中,**Circular View Path**错误常因视图解析与Controller路径重名引发。当视图名称(如`login`)与请求路径相同,Spring MVC无法区分,导致无限循环调用。解决方法包括:1) 明确指定视图路径,避免重名;2) 将视图文件移至子目录;3) 确保Spring Security配置与Controller路径一致。通过合理设定视图和路径,可有效避免该问题,确保系统稳定运行。
1039 0
|
Java 程序员
SpringBoot集成log4j2出现Logback configuration error detected: current ElementPath is
SpringBoot集成log4j2出现Logback configuration error detected: current ElementPath is
453 0
|
Java Spring
Spring Boot 启动报错解决:No active profile set, falling back to default profiles: default
Spring Boot 启动报错解决:No active profile set, falling back to default profiles: default
1308 0
|
JSON 数据库 数据格式
[Python]Django 视图(View)和URL 与 模板(Template)
[Python]Django 视图(View)和URL 与 模板(Template)
|
Java Maven 网络架构
【SpringBoot WebFlux 系列】WebFlux 之 Path 参数解析与 url 映射
接下来我们将进入 WebFlux 系列教程,努力使用最简明的语言,来介绍一下 WebFlux 的基本玩法,让各位小伙伴可以顺畅的切换和使用 WebFlux 来体验反应式编程的魅力 本文将主要介绍 WebFlux 提供 web 接口时的 url 匹配,以及对应的 path 参数解析
697 0
【SpringBoot WebFlux 系列】WebFlux 之 Path 参数解析与 url 映射
|
Java Android开发 Spring
javax.servlet.ServletException: Circular view path [hello]: would dispatch back to the current handl
javax.servlet.ServletException: Circular view path [hello]: would dispatch back to the current handl
831 0
javax.servlet.ServletException: Circular view path [hello]: would dispatch back to the current handl
|
Java 索引 Spring
Circular view path xxx would dispatch back to the current handler URL
版权声明:本文为 testcs_dn(微wx笑) 原创文章,非商用自由转载-保持署名-注明出处,谢谢。 https://blog.csdn.net/testcs_dn/article/details/79700275 ...
5738 0
|
缓存 安全 Java
Java服务器端技术:Servlet与JSP的集成与扩展
Java服务器端技术:Servlet与JSP的集成与扩展
327 3

热门文章

最新文章