这是我的第一个Spring Boot示例,第一步。我在STS 3.8中创建了一个SpringBoot项目,如下所示:
档案 - >新的Spring Starter项目
Dependecies - >网络
我在src / main / java / com.first.boot
中创建了以下控制器的IndexController 包com.first.boot;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class IndexController {
@RequestMapping("/")
public String index(){
return "index";
}
}
接下来,我在src / main / resources / templates中创建了视图index.html:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Welcome to your first Spring Boot Page
</body>
</html>
然后我将项目运行为: 右键单击项目 - &gt;以 - &gt;运行Spring Boot App
控制台显示正确的映射和Tomcat启动信息
Mapped "{[/]}" onto public java.lang.String com.first.boot.IndexController.index()
Tomcat started on port(s): 8080 (http)
Started FirstSpringBootApplication in 4.096 seconds (JVM running for 4.843)
Initializing Spring FrameworkServlet 'dispatcherServlet'
FrameworkServlet 'dispatcherServlet': initialization started
FrameworkServlet 'dispatcherServlet': initialization completed in 64 ms
但是每当我在浏览器上运行localhost:8080时,我都会看到这个页面:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Tue Dec 13 08:22:13 IST 2016
There was an unexpected error (type=Not Found, status=404).
No message available
控制台没有错误。
答案 0 :(得分:1)
添加以下依赖项解决了这个问题:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>