2016-12-13 96 views
1

这是我的第一个春天启动例子,上迈出的第一步。我在STS 3.8中创建一个SpringBoot项目是这样的:春天启动的观点不工作

文件 - >新建春季启动项目
依赖条件 - >网络

我的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"; 
    } 
} 

接下来,我创建的视图的index.html放在src /主/资源/模板:

<!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> 

然后我跑项目为: 右键单击项目 - >运行方式 - >春启动应用

控制台显示正确的映射和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 

但每当我本地主机上运行:在浏览器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 

有控制台没有错误。

回答

1

添加以下依赖解决该问题:

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-thymeleaf</artifactId> 
</dependency>