This is my first Spring Boot example and on the first step. I created a SpringBoot project in STS 3.8 like this:
File -> New Spring Starter Project
Dependecies -> Web
I created the following controller in src/main/java/com.first.boot
IndexController package 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";
}
}
Next, I created view index.html in src/main/resources/templates:
<!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>
Then I run the project as: Right click on project -> Run as -> Spring Boot App
The console shows proper mappings and Tomcat startup information
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
But whenever I run localhost:8080 on browser, I see this page:
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
There are no errors in console.