3

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

1
  • What is the value of server.contextPath property? Commented Oct 12, 2016 at 21:56

2 Answers 2

8

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=/)
Sign up to request clarification or add additional context in comments.

Comments

0

I have a html file in src/main/resources/static folder and added below in application.yml but it didn't work for me either. On tomcat start ,localhost:8080 shows a 404 and webpage shows whitelabel error. But for localhost:8080/hello.html I see a 200 response code when inspect but no contents of html on webpage .

server:
  servlet:
    context-path: /
  port: 8080

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.