我是 Spring 的新手,我发现它真的很难上手。我想提供静态 index.html,但它不起作用。
我用了this教程,但无法通过以下方式访问 index.html: http://localhost:8080/或者 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..
最佳答案
你能试试下面的方法吗:
- 移动
index.html
到src/main/resources/static
文件夹 - 在spring boot的application.properties文件中,将
server.contextPath
设置为/
。 (即server.contextPath=/
)
关于java - 无法使用 Spring Boot 提供静态 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40008958/