【问题标题】:Spring Boot + Web + Thymeleaf: Circular view path in Spring IO Guide for "Securing a Web Application"Spring Boot + Web + Thymeleaf:Spring IO Guide for "Securing a Web Application" 中的圆形视图路径
【发布时间】:2018-10-14 12:04:03
【问题描述】:

我正在试用 https://spring.io/guides/gs/securing-web/ 上提供的“保护 Web 应用程序”的 Spring IO 指南。

该指南指示首先构建一个简单的不安全的 Web 应用程序,然后使用 Spring Security 对其进行保护。但是,在使用 Spring Boot 2.0.1.RELEASE 版本构建不安全的 Web 应用程序后,尝试访问 Web 应用程序的 URL (http://localhost:9191/hello) 时出现以下错误:

2018-05-04 09:58:07.742 ERROR 25968 --- [nio-9191-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [hello]: would dispatch back to the current handler URL [/hello] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause    

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

我复制了上述 URL 中可用的代码(即https://spring.io/guides/gs/securing-web/),并且我的嵌入式 tomcat 服务器在端口 9191 上运行(因为端口 8080 被其他一些应用程序使用)。任何帮助表示赞赏。提前致谢!

编辑:

以下是指南中的配置/控制器代码:

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/home").setViewName("home");
        registry.addViewController("/").setViewName("home");
        registry.addViewController("/hello").setViewName("hello");
        registry.addViewController("/login").setViewName("login");
    }

}

【问题讨论】:

  • 不,不是重复的。
  • 您应该发布该路径的控制器。
  • 我提供了包含完整源代码的相关 Spring 指南的链接,因此,我没有在我的帖子中复制代码。但是,我将编辑帖子并提供指南中的控制器代码。谢谢!

标签: spring spring-mvc spring-boot spring-security


【解决方案1】:

请在您的pom 中添加thymeleaf 的依赖项。由于thymeleafViewResolver 不存在以解决您的hello.html 中的th:href="@{/hello},因此抛出错误:

在您的 pom 中添加以下依赖项。

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

【讨论】:

    【解决方案2】:

    检查构建路径中的 spring-boot-starter-thymeleaf 依赖项

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-25
      • 1970-01-01
      • 2018-03-08
      • 2014-03-29
      • 2012-05-20
      • 2016-06-28
      • 2015-01-22
      • 2016-04-01
      相关资源
      最近更新 更多