spring-restdocs - 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 Boot 将自动在/
. static/
它通过查看您的 jar文件夹(以及其他地方)来查找这些资源。您已将文档打包,static/docs
这意味着它可以从以下位置获得,/docs/
但您正在向/index.html
. 请求/docs/index.html
应与文档一起响应。
推荐阅读
- sql - 为什么我在这 2 个 SQL 查询中得到不同的结果?单独使用 AVG 与使用 over() 时
- c++ - 使用多个插入准备查询
- sql - 使用变量时 SQL 查询不给出输出
- python-3.x - 在 django 中注销使用 HTTP Apache LDAP 登录的用户的解决方法
- c++ - 无法始终为具有 #pragma 或项目警告级别的标头禁用 Visual Studio 2019 警告
- eof - 文件结束语法-Reg
- android - NativeActivity vs NDK JNI vs SDK
- javascript - 条纹结帐,付款后获取数据
- python-3.x - 加快 difflib 查找 get_close_matches() 函数
- flutter - 我正在使用 Flutter 文本字段(不是文本表单字段)制作温度转换器应用程序我需要限制多个点和多个符号 (+ - )?