javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handl

Posted 闲言博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handl相关的知识,希望对你有一定的参考价值。

错误产生环境

SpringBoot项目 整合thymeleaf 时产生

错误描述

javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handler URL [/index] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
	at org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:210) [spring-webmvc-5.3.6.jar:5.3.6]
	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:148) [spring-webmvc-5.3.6.jar:5.3.6]
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) [spring-webmvc-5.3.6.jar:5.3.6]
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1393) [spring-webmvc-5.3.6.jar:5.3.6]
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1138) [spring-webmvc-5.3.6.jar:5.3.6]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1077) [spring-webmvc-5.3.6.jar:5.3.6]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962) [spring-webmvc-5.3.6.jar:5.3.6]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.6.jar:5.3.6]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.3.6.jar:5.3.6]

错误原因

  • 控制层代码

    templates 目录下也有index.html文件


为什么我访问网站根 目录时产生错误呢

原因竟然是我thymeleaf 的依赖导入错误,导致了异常的产生

解决办法

导入正确的依赖即可

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


请求成功

以上是关于javax.servlet.ServletException: Circular view path [index]: would dispatch back to the current handl的主要内容,如果未能解决你的问题,请参考以下文章