Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring does not show home.html

I am learning Spring Framework. I added home.html in resources/templates/home.html. But it is not visible when I visit http://localhost:8080. I have the following structure:

taco-cloud\src\main\java\tacos\TacoCloudApplication.java

package tacos;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TacoCloudApplication {

    public static void main(String[] args) {
        SpringApplication.run(TacoCloudApplication.class, args);
    }

}

taco-cloud\src\main\java\tacos\HomeController.java

package tacos;

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

@Controller
public class HomeController 
{
    @GetMapping("/")
    public String home()
    {
        return "home.html";
    }
}

taco-cloud\src\main\resources\static\home.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:th="http://www.thymeleaf.org">
 <head>
 <title>Taco Cloud</title>
 </head>
 <body>
 <h1>Welcome to...</h1>
 <img th:src="@{/images/TacoCloud.png}"/>
 </body>
</html>

Output

Whitelable error page

localhost:8080/home.html show home.html

like image 995
Aman Avatar asked Mar 07 '26 05:03

Aman


1 Answers

You have to change the location of your home page to be in the static folder :

resources/static/home.html
          ^^^^^^

instead of

resources/templates/home.html

and specify the extension in your controller :

return "home.html";
            ^^^^^

else you have to create a view resolver to avoid using extensions and to specify the other locations of your pages take a look at Configure ViewResolver with Spring Boot and annotations gives No mapping found for HTTP request with URI error

like image 61
YCF_L Avatar answered Mar 09 '26 18:03

YCF_L



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!