There is a controller

@Controller public class MainController { @GetMapping("/") public String index(){ return "index"; } @GetMapping("login") public String login(){ return "/login"; } } 

And in the src / main / resources / templates directory there are two files: index.html, login.html. When I launch the application and go over zamaplennymi urla, then I see the ekseptsii: at / login

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

and at the start page, just error 404. Here is an example of the start page / login:

 <!DOCTYPE HTML> <head> <title>Ght</title> </head> <body> <a href="@{/login}">test</a> </body> </html> 

I don’t understand why such a trivial thing doesn’t work (Google told about the @EnableMvc annotation, but did not help) just in case the pom.xml file

 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>ru.myspringproject</groupId> <artifactId>telegraph</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>telegraph</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> 

in google also found that this behavior may be due to dependencies.

    2 answers 2

    It turned out that the problem is in the help file. I clearly indicated the version of the mysql driver (and for some reason, the observatory swore, perhaps because the version is automatically chosen for spring-boot-starter-parent), so I did not use the time-dependent dependency on the project, hence the error

      this code needs to be changed

        @GetMapping("login") public String login(){ return "/login"; } } 

      you need to put value in front of the login and add / and at the end if you make a return in jsp or thymeleaf you need to remove this / this code will look like this

        @GetMapping(value="/login") public String login(){ return "login"; } } 

      and what remains on jsp or thymeleaf this code in jsp will look like this

        <!DOCTYPE HTML> <head> <title>Ght</title> </head> <body> <a href="@{/login}">test</a> </body> </html> 

      jsp

        <!DOCTYPE HTML> <head> <title>Ght</title> </head> <body> <a href="/login">test</a> </body> </html> 

      if thymeleaf

      thymeleaf

        <!DOCTYPE HTML> <head> <title>Ght</title> </head> <body> <a th:href="@{/login}">test</a> </body> </html>