Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to serve static html content page in spring-boot

I'm starting an embedded tomcat via spring-boot and want to serve a static index.html page as part of a running application.

But the following does not work:

@SpringBootApplication
public class HMyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}


@RestController 
public class HomeContoller {
    @RequestMapping("/")
    public String index() {
        return "index";
    }
}

src/main/resources/static/index.html

Result: when I call localhost:8080, I just see the word "index", but not my html page. Why?

like image 297
membersound Avatar asked Sep 05 '25 01:09

membersound


1 Answers

My fault: I had an additional class with @EnableWebMvc annotation. This somehow messed up the spring-boot autoconfiguration. I removed it and now it works returning index.html.

like image 100
membersound Avatar answered Sep 07 '25 13:09

membersound