我正在学习Spring Boot并通过课程学习。请原谅我的新手。我已经搜索了这个错误,并尝试了我发现的建议,这对我没有用,所以我发布了这个问题。我希望有人可以帮助我。
目前这是一个非常简单的应用程序,我只是在使用http://localhost:8080/或http://localhost:8080/courses
时尝试调出courses.html我有一个course.html文件,位于文件夹src / main / resources / templates
中这是结果错误:
2018-06-04 15:51:59.928 ERROR 3156 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [courses]: would dispatch back to the current handler URL [/courses] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause
我的控制器中有这个代码:
@Controller
public class CourseController {
@RequestMapping(value="/")
public String rootPath() {
return "courses";
}
@RequestMapping(value="courses")
public String courses (ModelMap model) {
return "courses";
}
}
这是我的POM文件:
<?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>net.proffesso.videos</groupId>
<artifactId>CourseCreation</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>CourseCreation</name>
<description>CourseCreation project using Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.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-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
我读到的一条建议是说要从
更改Spring Boot启动器依赖项<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
到
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
我的POM文件中生成了这两个依赖项,如果我删除了spring-boot-starter-web,那么我在@Controller和@RequestMapping上会出现错误