首页 > 解决方案 > Spring Rest Docs 错误调用 docs/index.html

问题描述

当我调用 localhost:8080/index.html 时,我收到 404 错误。我正在使用 gradle 和 kotlin。这是我的 build.gradle.kts:

plugins {
    id("org.springframework.boot") version "2.2.3.RELEASE"
    id("io.spring.dependency-management") version "1.0.8.RELEASE"
    id("org.asciidoctor.convert") version "1.5.9.2"
    kotlin("jvm") version "1.3.61"
    kotlin("plugin.spring") version "1.3.61"

}

version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8

val snippetsDir = file("build/generated-snippets")

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    asciidoctor("org.springframework.restdocs:spring-restdocs-asciidoctor")
    testImplementation("org.springframework.boot:spring-boot-starter-test") {
        exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
    }
    testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")


}

tasks{

    withType<Test> {
        useJUnitPlatform()
    }

    withType<KotlinCompile> {
        kotlinOptions {
            freeCompilerArgs = listOf("-Xjsr305=strict")
            jvmTarget = "1.8"
        }
    }

    test {
        outputs.dir(snippetsDir)
    }

    asciidoctor {
        inputs.dir(snippetsDir)
        dependsOn("test")
    }

    asciidoctor{
        outputDir = file("build/docs")
    }



    bootJar {
        dependsOn("asciidoctor")
        from ("${asciidoctor.get().outputDir}/html5") {
            into("static/docs")
        }

    }
} 

知道我可能做错了什么吗?

Spring Rest Docs 是否支持 build.gradle.kts?从我在文档中看到的内容来看,我没有发现任何关于它的内容。

标签: spring-restdocs

解决方案


Spring Boot 将自动在/. static/它通过查看您的 jar文件夹(以及其他地方)来查找这些资源。您已将文档打包,static/docs这意味着它可以从以下位置获得,/docs/但您正在向/index.html. 请求/docs/index.html应与文档一起响应。


推荐阅读