Spring Boot - Error 404 nonsense

1

I'm starting with Spring boot and I created a project by Spring Initializr with Spring Boot 2.0.5 and dependencies Web, PostgreSQL e DevTools , I imported the project In IntelliJ, so far, I've been following some tutorials I've seen on the internet and created a package in the same place where the class is with @SpringBootApplication called controller and inside I created a class TesteController , with following code:

package com.projetospringboot.meuprojeto.controller;

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

@Controller
public class IndexController {

    @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String index() {
        System.out.println("entrou");
        return "index";
    }
}

and then in the folder templates I created an html file named index.html and executed the project, according to the tutorials I saw and with logic if I opened the browser and accessed localhost:8080/home it should show me the html that I did however it returns an error saying:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this 
as a fallback.

Mon Sep 17 17:37:48 BRT 2018
There was an unexpected error (type=Not Found, status=404).
No message available

And what I understood from this error is that it nn has a route mapped to /error and this I see how to solve later because what it means is that it gave a 404 error and that as nn has a route to /error he showed it, the question is, why is he giving 404 error? I have tried to change the return of method index() to all type of route "./index", "../index", "templates/index", "./templates/index", "index.html", "./index.html" and etc .. but none worked.

Here is a print of the hierarchy of project folders:

theclasscodewiththemainmethod:

packagecom.projetospringboot.meuprojeto;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.context.annotation.ComponentScan;@SpringBootApplication@ComponentScan({"com.projetospringboot.meuprojeto.controller"})
public class MeuProjetoApplication {

    public static void main(String[] args) {
        SpringApplication.run(MeuProjetoApplication.class, args);
    }
}
    
asked by anonymous 17.09.2018 / 22:58

1 answer

0

Place the main application class above the other packages. Change to the packages perspective in Intellij and check if the class containing the @SpringBootApplication annotation is in the root.

    
19.09.2018 / 22:00