Spring Boot Whitelabel Error page (type=Not Found, status=404)

verify that you have the correct thymeleaf dependency within your pom.xml:

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

Make sure that your main class is in a root package above other classes.

When you run a Spring Boot Application, (i.e. a class annotated with @SpringBootApplication), Spring will only scan the classes below your main class package.

So your declaration goes like this

package br.com.SpringApp.SpringApp; inside this main class i.e SpringAppApplication

package br.com.SpringApp.SpringApp.controller; name of your controllers i.e EventoController & indexControllers

package br.com.SpringApp.SpringApp.model; name of your models i.e Evento

After This clean your project and re-run spring boot application;


Solution: If you are using @Controller over the Controller class then it will be treated as a MVC controller class. But if you want a special controller used in RESTFul web services then you to use @Controller along with @ResponseBody annotation or you can directly use @RestController over the Controller class. It worked for me as I was getting the same error while creating SpringBoot project with RestFul webservices.

package br.com.SpringApp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class EventoController {

    @RequestMapping("/cadastroEvento")
    @ResponseBody
    public String form() {      
        return "evento/formEvento"; 
    }

}

or:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@RestController
public class EventoController {

    @RequestMapping("/cadastroEvento")
    public String form() {      
        return "evento/formEvento"; 
    }

}