我遇到了一个问题,这是一个全新的项目。所有代码都只是在 main 中运行应用程序。我正在尝试将 index.html 设置为主页。文档说将这个文件放在 src/main/resources/static (或公共)中就足够了。但是这个页面没有显示给我。可能是什么原因
plugins {
id 'org.springframework.boot' version '2.2.0.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly}}
repositories {
mavenCentral()}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
您应该尝试检查以下选项:
查看 application.properties 中指定了什么 server.port,可能不是 8080。
重建项目(输入 gradle build 命令),可能 index.html 没有添加到程序集中。
尝试去掉spring-boot-starter-thymeleaf 库,然后静态文件夹中默认的 index.html 会返回获取请求http://localhost:port/
如果添加了spring-boot-starter-thymeleaf库,那么您可以将 index.html 文件传输到模板文件夹 并添加类