1

I am trying out the Spring IO Guide for "Securing a Web Application" available at https://spring.io/guides/gs/securing-web/.

The guide instructs to build a simple unsecured web application first and secure it using Spring Security later. However, after building the unsecured web application with Spring Boot 2.0.1.RELEASE version, I am getting the following error on trying to access a URL (http://localhost:9191/hello) of the web application:

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.)    

I replicated the code as available at the above URL (i.e. https://spring.io/guides/gs/securing-web/) and my embedded tomcat server is running on port 9191 (as port 8080 is used by some other app). Any help is appreciated. Thanks in advance!

Edit:

Following is the configuration/controller code from the guide:

@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");
    }

}
user3886219
  • 101
  • 5
  • Possible duplicate of [How to avoid the "Circular view path" exception with Spring MVC test](https://stackoverflow.com/questions/18813615/how-to-avoid-the-circular-view-path-exception-with-spring-mvc-test) – Mehraj Malik May 04 '18 at 05:50
  • No, it's not a duplicate. – user3886219 May 04 '18 at 10:15
  • You should post the controller for that path. – Bennett Dams May 04 '18 at 11:07
  • I provided link to relevant Spring Guide that contains full source code and hence, I didn't replicate the code in my post. However, I will edit the post and provide the controller code from the guide. Thanks! – user3886219 May 04 '18 at 14:27

2 Answers2

3

Please add dependency for thymeleaf in your pom. as ViewResolver of thymeleaf is not present to resolve th:href="@{/hello} in your hello.html so throwing error:

Add below dependency in your pom.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
kj007
  • 6,073
  • 4
  • 29
  • 47
0

check spring-boot-starter-thymeleaf dependency in your build path

overfight
  • 43
  • 1
  • 6