Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't serve static index.html with Spring Boot

I'm new to Spring and I find it is really hard to get into it. I want to serve a static index.html but it doesn't work. enter image description here

I used this tutorial but can't access index.html with: http://localhost:8080/ or http://localhost:8080/src/main/public/index.html

IndexHtmlController:

package de.phip1611.springboot_test_1;

import org.springframework.stereotype.Controller;

@Controller
public class IndexHtmlController {}
// due to https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot
// this should be enough..

enter image description here

like image 216
phip1611 Avatar asked Jan 01 '26 19:01

phip1611


1 Answers

Can you try the below:

  1. Move index.html to src/main/resources/static folder
  2. In the application.properties file of spring boot, set server.contextPath to /. (i.e. server.contextPath=/)
like image 152
Darshan Mehta Avatar answered Jan 03 '26 07:01

Darshan Mehta



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!