【发布时间】:2017-04-28 01:09:29
【问题描述】:
这是我的第一个 Spring Boot 示例,也是第一步。我在 STS 3.8 中创建了一个 SpringBoot 项目,如下所示:
文件 -> 新建 Spring Starter 项目
依赖项 -> 网络
我在 src/main/java/com.first.boot 中创建了以下控制器
索引控制器 包 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>
然后我将项目运行为: 右键项目->运行方式->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
控制台没有错误。
【问题讨论】:
标签: spring-boot