【发布时间】: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