I'm setting a spring boot project with thymeleaf but my view isn't displaying and getting the following error in the browser.
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Fri May 24 00:44:22 GST 2019 There was an unexpected error (type=Not Found, status=404). No message available
pom.xml:
<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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
Controller:
@Controller
public class MainController {
@GetMapping("/")
public String homePage() {
return "home";
}
}
application.properties:
spring.thymeleaf.cache=false
spring.thymeleaf.enabled=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.application.name=Bootstrap Spring Boot
I had added thymeleaf feature in my html file, but when it wasn't working I just made it simple html file. My home.html is:
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Hello !</h1>
<p>
Welcome to Our App</span>
</p>
</body>
</html>
It's a very simple and basic controller. I am not seeing any exception stack trace in the console.
After a couple of days of effort, I resolved this issue by downgrading spring boot version from 2.1.5 to
<version>2.0.6.RELEASE</version>